我正在使用jQuery的Uploadify插件来上传一个文件。我遇到的一件事是,我需要能够重命名上传的文件,以便我可以将该信息发布到将数据插入mysql数据库的脚本中。有没有人能建议一下该怎么做?
谢谢,杰克
发布于 2012-06-05 20:04:20
你可以这样做:
$targetFolder = FCPATH.'/resources/images/users/temp/'; // Relative to the root
if (!empty($image))
{
$time=strtotime("now");
$image['Filedata']['name']=$time.'.jpg';
$tempFile = $image['Filedata']['tmp_name'];
$targetPath = $targetFolder.$image['Filedata']['name'];
// Validate the file type
$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
$fileParts = pathinfo($image['Filedata']['name']);
if (in_array($fileParts['extension'],$fileTypes))
{
move_uploaded_file($tempFile,$targetPath);
echo '1';
}
else
{
echo 'Invalid file type.';
}
}发布于 2013-05-07 01:44:32
首先,在uploadify.php中根据需要重命名文件名
然后你只需要从你的uploadify.php文件返回$targetPath,就像这样--
echo $targetPath
不需要使用echo“%1”
现在,您必须获得重命名的文件名。您可以在onUploadSuccess函数中获得此函数。onUploadSuccess()接受三个参数(文件、数据、响应),
其中,file提供您通过计算机浏览的文件的实际名称,而data提供您根据需要通过uploadify.php代码生成的重命名文件名。
所以你可以试试下面的代码--
'onUploadSuccess' : function(file, data, response) {
alert('Renamed file name is - ' + data);
}我希望这能有所帮助。我的一个朋友告诉我这个,然后我就完成了我的工作:)
发布于 2010-09-01 12:05:45
如果您使用uploadify.php,只需转到函数move_uploaded_files之前并更改目标名称。
无论如何,如果你这样做了,这应该是可行的。如果您需要更详细的答案,请将您已有的代码张贴出来。
https://stackoverflow.com/questions/3614966
复制相似问题