开发者

How to trim uploaded file name's length to 10 chars when using Drupal CCK file fields?

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+ "...");
    }
  });
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜