I uploaded 1 file and name it "test-test-test-test-test.php". It create problem in my l开发者_运维问答ayout. my layout is mess up. so if i upload file name up to 10 char then its fine.
Rename it before uploading.
In PHP:
<?php
$filename = 'test-test-test-test-test.php';
rename($filename, substr($filename, 0, 10) . '.php'));
?>
Single line solution
<?
$filename="test.php";
$filename=str_pad(trim($filename), 10, "123456789", STR_PAD_LEFT);
echo $filename;
//12test.php
$filename="test.php";
$filename=str_pad(trim($filename), 14, "123456789", STR_PAD_LEFT);
echo $filename;
//123456test.php
?>
$filename = 'testtesttesttesttesttest.php';
$filename = basename($path, ".php");
$filename = substr($filename, 0, 10);
$filename .= '.php';
I found the solution. Its using jquery.
jQuery("div.files .view-content .views-field-field-file-file-fid .filefield-file a")
.each(function(){
var file_text = jQuery(this).text();
if(file_text.length > 10){
file_sub_text = file_text.substring(0,10);
jQuery(this).text(file_sub_text+ "...");
}
});
精彩评论