Reputation: 335
I have a form that uploads images < 500kb The issue I'm encountering is that the uploaded image on the server is partially visible / missing part of the image.
Does anyone know what could be the issue?
if(isset($_POST['Submit']))
{
$image = $_FILES['image']['name']; //reads the name of the file the user submitted for uploading
if ($image) //if it is not empty
{
$filename = stripslashes($_FILES['image']['name']); //get the original name of the file from the clients machine
$extension = getExtension($filename);//get the extension of the file in a lower case format
$extension = strtolower($extension);
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")){
echo '<h1>Error, allowed only: .jpg, .png, .gif</h1>';
$errors=1;
}else{
$size = filesize($_FILES['image']['tmp_name']);
if ($size > 512000){
echo '<h1 style="color:red;">Too big (Max: 500KB). Try again. </h1>';
$errors=1;
}else{ //MAX SIZE IS SMALLER
$s = $_POST['first_name'];
$ts = array("/ä/","/Ä/");
$tn = array("a","A");
$image_name= preg_replace($ts,$tn, str_replace(' ','+',$s)).'_'.time().'.'.$extension; // $image_name=time().'.'.$extension;
$newname="img/uploads/images/".$image_name;
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied)
{
echo '<h1>Could not upload image</h1>';
$errors=1;
}
}
}
}
}
^^^^ more of image is missing
Upvotes: 2
Views: 1101
Reputation: 3345
The image you uploaded is truncated so it's fair to assume the file didn't complete uploading. Maybe the temporary directory is full on the server, maybe you're over your quota on your server. I've tested your code on my server and there's no problems here.
Upvotes: 3