因此,我正在嘗試按照本教程here的說法,但我很難讓它按照預期的方式工作。所以我創建了一個名爲fileToUpload
的文件,在這個文件中我有四個文件。首先,php.ini
用下面的代碼:使用PHP上傳圖片到文件夾中
file_uploads = On
二,upload.html
:
<!DOCTYPE html>
<html>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="fileToUpload" id="fileToUpload">
<input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>
三,upload.php
:
<?php
$target_dir = "uploads/";
$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 "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
?>
最後,我有一個名爲uploads
文件夾,用裏面什麼也沒有該文件夾。我應該注意到upload.html
,upload.php
和php.ini
都在一個名爲fileToUpload
的文件夾中。
現在,當我點擊提交按鈕時,它顯示upload.php
內部的代碼,uploads
文件夾內沒有任何內容。但是,它應該將上傳的文件放入uploads
文件夾中。但是,它不起作用。
寫正確確保您的上傳文件夾搭配chmod 777以及 –
什麼是搭配chmod 777? –