上传后重命名某些文件? [英] Renaming certain files after upload?
本文介绍了上传后重命名某些文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
大家好,我有一个脚本进行了部分编辑,以仅接受要上载的某些文件类型,例如; JPG,PNG,JPEG等.该脚本最初是"uploadify脚本"的一部分,是php的新功能,因此im很难解决我如何添加功能以在后端重命名文件,这样我就不会出现重复或错误在上传时,但保留前端的原始名称.如果一切都有意义,请先谢谢-Cody
Hi all, i''ve got a script that i''ve part edited to accept only certain file types to be uploaded, eg; JPG, PNG, JPEG etc. the script is originally part of the "uploadify script", im new to php so im finding it hard to work out how i can add a function to rename files on the backend so i dont get duplicates or errors on upload, but keep original names for the frontend. if this all makes sense, thanks in advance - Cody
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/';
$targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name'];
$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (in_array($fileParts['extension'],$fileTypes)) {
move_uploaded_file($tempFile,$targetFile);
echo '1';
} else {
echo 'Invalid file type.';
}
}
?>
[edit]仅标记-OriginalGriff [/edit]
[edit]Tags only - OriginalGriff[/edit]
推荐答案
_FILES)){
_FILES)) {
tempFile =
tempFile =
_FILES [ ' 文件数据'] [' tmp_name' ];
_FILES['Filedata']['tmp_name'];
这篇关于上传后重命名某些文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文