使用PHP将文件上传到文件夹时遇到麻烦。我当前的错误是。我似乎无法真正使它正常工作,可能是由于move_uploaded_file所致,但是目前我还不知道。错误不是程序的主要问题,整个问题都不起作用。我是学生,还在学习,所以请保持友善<3
Notice: Undefined index: fileToUpload in I:\The_Better_Local_Server\root\testwebpage.php on line 16
Notice: Undefined index: file in I:\The_Better_Local_Server\root\testwebpage.php on line 19
Notice: Undefined index: file in I:\The_Better_Local_Server\root\testwebpage.php on line 22
Sorry, there was an error uploading your file.
我的代码在下面列出:
line8 -<form action="testwebpage.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>
<?php
$target_dir = "I:\The_Better_Local_Server\root\Pictures";
$target_file = $target_dir.basename($_FILES["fileToUpload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
move_uploaded_file( $_FILES['file']['tmp_name'], $target_file );
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);z
if($check !== false) {
echo "File is an image - " . $check["mime"] . ".";
$uploadOk = 1;
} else {
echo "File is not an image.";
$uploadOk = 0;
}
}
if(move_uploaded_file($_FILES["file"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["file"]["name"]). " has been uploaded.";
} else {
echo "Sorry, there was an error uploading your file.";
}
-line 28 -?>