所以我有一個問題,讓我的文件上傳到我想 它。它執行一切,但不會上傳文件。它只是 說:上傳一個文件在PHP不能工作
你的文件有問題。
這是我的代碼:感謝您的幫助!
P.S.我試圖上傳的文件是11kb大,所以尺寸不是 問題。此外,權限不是問題。
<p>The file must be an image and less than 2 MB.</p>
<form action="filerupp.php" method="post" enctype="multipart/form-data">
<p>Choose file:<br/>
<input type="file" name="fileToUpload" id="fileToUpload"><br/>
<input type="submit" value="Upload image" name="submit"></p>
</form>
<p>Files are <a href='pictures'>here</a>.</p>
這裏是我的PHP代碼:
$target_dir = "pictures/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
if($check !== false) {
echo "<p>The File is an image" . $check["mime"] . ".<br/>";
$uploadOk = 1;
} else {
echo "<p>The File is not an image.<br/>";
$uploadOk = 0;
}
}
// Check if file already exists
if (file_exists($target_file)) {
echo "<p>Sorry, the file already exists.<br/>";
$uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 500000) {
echo "Sorry, the file är för stor.<br/>";
$uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
&& $imageFileType != "gif") {
echo "Sorry, only JPG, JPEG, PNG & GIF.<br/>";
$uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
echo "Sorry, your file cannot be uploaded.</p>";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "<p>The file ". basename($_FILES["fileToUpload"]["name"]). " has been uploaded and is <a href='pictures'>here</a>.</p>";
} else {
echo "<p>Sorry, there was something wrong with your file.</p>";
}
}
檢查文件夾 – urfusion
的權限http://php.net/manual/en/features.file-upload.post-method.php按照此鏈接或可能檢查您的文件夾權限上傳圖像的位置。如果沒有解決與我聯繫。 skype:harryr891 –
這是在Linux還是Windows? – infinigrove