我的任務需要我讓用戶將.gif文件擴展名上傳到文件夾,並在上傳後顯示它們。PHP。上傳.gif文件到服務器
我得到了表格和處理頁面,但我似乎無法讓他們工作。我將目錄上的權限設置爲rwxrwxrwx來測試它。
上傳文件代碼:
<html>
<head>
<title>Assignment 7 Part II -- Art Gallery</title>
</head>
<body>
<form method="post" action="a7a2.php" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="50000">
Your file: <input type="file" name="uploadFile" /><br />
<input type="submit" value="Upload it">
</form>
</body>
</html>
代碼:
<html>
<head>
<title>Assignment 7 Part II -- Art Gallery Results</title>
</head>
<body>
<?php
$uploadDir = 'images/';
$uploadFileDir = $uploadDir . basename($_FILES['uploadFile']['name']);
if(isset($_FILES['uploadFile'])) {
if($_FILES['uploadFile']['error'] != UPLOAD_ERR_OK ||
$_FILES['uploadFile']['mime'] != "image/gif") {
print "<p>File not uploaded successfully!</p>";
print "<p>Please make sure the file has the correct file extension: .gif</p>";
print "<p><a href='a7p2.php'>Try uploading again</a>";
var_dump($_FILES['uploadFile']['error']);
die;
} else {
move_uploaded_file($_FILES['uploadFile']['name'], $uploadFileDir) or die("Can't move file to $uploadFileDir");
print "<p>Success!</p>";
}
}
$uploadedFiles = glob("/students/ryan/php/images/*.gif");
if($uploadedFiles != false) {
print "<p>Here are pictures from the art gallery: </p>";
foreach($uploadedFiles as $file) {
$url = "http://hills.ccsf.edu/~ryan/images/" . substr($file, strrpos($file, '/') + 1);
print "<p><img src=\"$url\"></p>";
}
} else {
print "There are no pictures in the art gallery";
}
?>
</body>
</html>
或相同的代碼,鏈接下面的代碼:
你能否詳細說明爲** **如何這不是加工? – Archimaredes
它一直說文件沒有成功上傳。請確保文件具有正確的文件擴展名。嘗試再次上傳 – yan
嘗試在整個'$ _FILES ['uploadFile']上執行'var_dump''當您看到設置。看看它包含什麼。 – LSerni