提问人:Anup.D.T 提问时间:11/5/2023 最后编辑:AdiAnup.D.T 更新时间:11/8/2023 访问量:33
为什么没有使用php表单将图像文件上传到特定文件夹
Why is the image file not being uploaded to a specific folder using php forms
问:
这是我的代码,它选择图像文件并上传到指定的文件夹上。但是我在程序中遇到了问题。所选文件不会上传到分配给的“fillll”文件夹,而是上传到“Pictues”文件夹。
如何纠正此行为?$target_dir
<?php
if($_SERVER["REQUEST_METHOD"]==="POST"){
if (isset($_FILES['fileToUpload']) && !empty($_FILES['fileToUpload']['name'])) {
$target_dir = 'C:/Users/HP-PC/Pictures/filll';
$target_file = $target_dir . basename($_FILES['fileToUpload']['name']);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file, PATHINFO_EXTENSION));
$fileError="";
$succsess="";
$check = getimagesize($_FILES['fileToUpload']['tmp_name']);
if ($check !== false) {
$success = "File is an image - " . $check['mime'] . ".<br>";
$uploadOk = 1;
} else {
$fileError .= "File is not an image.<br>";
$uploadOk = 0;
}
if (file_exists($target_file)) {
$fileError .= "Sorry, file already exists.<br>";
$uploadOk = 0;
}
if ($_FILES["fileToUpload"]["size"] > 500000) {
$fileError.="Sorry, your file is too large.<br>";
$uploadOk = 0;
}
if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" ) {
$fileError .= "Sorry, only JPG, JPEG, PNG & GIF files are allowed.<br>";
$uploadOk = 0;
}
if ($uploadOk == 0) {
$fileError .="Sorry, your file was not uploaded.<br>";
// if everything is ok, try to upload file
} else {
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
$fileError .="The file ". htmlspecialchars( basename( $_FILES["fileToUpload"]["name"])). " has been uploaded.<br>";
} else {
$fileError.= "Sorry, there was an error uploading your file.<br>";
}
}
}else{
$fileError="Plz select the file";
}
}
?>
答: 暂无答案
下一个:当我按下按钮时,什么也没发生
评论
$target_dir
'C:/Users/HP-PC/Pictures/filll'
$target_file
$target_dir