I'm trying to upload a picture but it gave me an error related to XAMPP. The image I was trying was a jpg image so I don't think that is the issue. I am not sure what I did wrong or what to rearrange in order for the image to be accepted.
if(isset($_FILES["image"]) && $_FILES["image"]["error"] == 0){
$allowed = array("jpg" => "image/jpg", "jpeg" => "image/jpeg", "png" => "image/png");
$filename = $_FILES["image"]["name"];
$filetype = $_FILES["image"]["type"];
$filesize = $_FILES["image"]["size"];
$ext = pathinfo($filename, PATHINFO_EXTENSION);
if(!array_key_exists($ext, $allowed)) die("Error: Please select a valid file format.");
$maxsize = 10 * 1024 * 1024;
if($filesize > $maxsize) die("Error: File size is larger than the allowed limit.");
if(in_array($filetype, $allowed)){
if(file_exists("upload/" . $filename)){
echo $filename . " is already exists.";
} else{
if(move_uploaded_file($_FILES["image"]["tmp_name"], "upload/" . $filename)){
$sql="INSERT INTO images(file,type,size) VALUES('$filename','$filetype','$filesize')";
mysqli_query($conn,$sql);
echo "Your file was uploaded successfully.";
}else{
echo "File is not uploaded";
}
}
} else{
echo "Error: There was a problem uploading your file. Please try again.";
}
} else{
echo "Error: " . $_FILES["image"]["error"];
}
}```
source https://stackoverflow.com/questions/71399828/move-uploaded-file-unable-to-move-c-xampp-tmp-php39b2-tmp-to-upload
No comments:
Post a Comment