如何上传文件的不同副本?

时间:2015-07-01 16:48:17

标签: image upload filenames

我需要有关如何使代码获取图像文件,重命名并上传单独副本的帮助。我希望原始副本完全保留原样。

<?php
$fileName = $_FILES["uploaded_file"]["name"];
$fileTmpLoc = $_FILES["uploaded_file"]["tmp_name"];
$fileType = $_FILES["uploaded_file"]["type"]; 
$fileSize = $_FILES["uploaded_file"]["size"]; 
$fileErrorMsg = $_FILES["uploaded_file"]["error"]; 
$fileName = preg_replace('#[^a-z.0-9]#i', '', $fileName); 
$kaboom = explode(".", $fileName); 
$fileExt = end($kaboom); 
$fileName = rand(1, 10).".".$fileExt;

if (!$fileTmpLoc) { 
    echo "ERROR: Please browse for a file before clicking the upload   button.";
    exit();
} else if($fileSize > 5242880) {
    echo "ERROR: Your file was larger than 5 Megabytes in size.";
    unlink($fileTmpLoc); 
    exit();
} else if (!preg_match("/.(gif|jpg|png)$/i", $fileName) ) {

     echo "ERROR: Your image was not .gif, .jpg, or .png.";
     unlink($fileTmpLoc); 
     exit();
} else if ($fileErrorMsg == 1) { 
    echo "ERROR: An error occured while processing the file. Try again.";
    exit();
}

$moveResult = move_uploaded_file($fileTmpLoc, "uploads/$fileName");
if ($moveResult != true) {
    echo "ERROR: File not uploaded. Try again.";
    exit();
}

echo "The file named <strong>$fileName</strong> uploaded successfuly.<br /><br />";
echo "It is <strong>$fileSize</strong> bytes in size.<br /><br />";
echo "It is an <strong>$fileType</strong> type of file.<br /><br />";
echo "The file extension is <strong>$fileExt</strong><br /><br />";
echo "The Error Message output for this upload is: $fileErrorMsg";
?>

有人可以帮忙吗?

0 个答案:

没有答案