我想在上傳圖片時更改圖片名稱。上傳時更改圖片名稱
這裏是我的代碼:
if(isset($_POST['submit']))
{
$target_dir = "pictures/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Allow certain file formats
if($imageFileType != "gif") {
echo "Sorry only GIF files are allowed.";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file was not uploaded.";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file ". basename($_FILES["fileToUpload"]["name"]). " has been uploaded.";
header('Location:field_medal_winner.php');
} else {
echo "Sorry, there was an error uploading your file.";
}
}
}
首先我試圖做到這一點蒙山改變move_uploaded_file功能。 但我剛剛得到了其他信息:
if (move_uploaded_file("text.gif", $target_file)) {
echo "The file ". basename($_FILES["fileToUpload"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
有沒有人有一個想法是什麼,我做錯了什麼?
你頭前正在輸出 - 檢查http://php.net/manual/en/function.error-reporting.php和形式的未知。 *「但我剛剛收到其他消息」* - 因爲有錯誤。 –
可能重複的[如何修復]頭文件已發送「PHP中的錯誤」(http://stackoverflow.com/questions/8028957/how-to-fix-headers-already-sent-error-in-php) –
可能[如何重命名上傳的文件,然後將其保存到一個目錄?](http://stackoverflow.com/questions/18705639/how-to-rename-uploaded-file-before-saving-it-into-a-directory ) –