I'm creating a website where I need to use a jQuery zoom script. the problem is I need a 4x larger image of the original file uploaded by the admin. The code i wrote is:
$allowedExts = array("jpeg", "jpg");
$extension = end(explode(".", $_FILES["file"]["name"]));
if (in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
$out = "Error: " . $_FILES["file"]["error"] ."<br>";
}
else
{
$fname = "img/" . $_POST["map"] . "." . $extension;
move_uploaded_file($_FILES["file"]["tmp_name"], $fname);
//crear imagen grande
if(file_exists($fname)){
list( $width, $height ) = getimagesize($fname);
$nwidth = $width * 4;
$nheight = $height * 4;
$nimage = imagecreatetruecolor( $nwidth, $nheight );
$image = imagecreatefromjpeg( $fname );
if(imagecopyresampled( $nimage, $image, 0, 0, 0, 0, $nwidth, $nheight, $width, $height)){
$nfname = "img/" . $_POST["map"] . "_big." . $extension;
imagejpeg( $nimage, $nfname, 100 );
}
else{
echo "Failed At re-sizing the image";
}
imagedestroy($image);
imagedestroy($nimage);
}
else{
echo "Can't find the file";
}
$out = $_FILES["file"]["name"] . " has been uploaded sucessfully <br>";
}
}
else
{
$out = "Invalid file (JPG-JPEG Only)<br>";
}
And the form that sends the file is:
<form action="handler.php" method="post"
enctype="multipart/form-data">
<label for="file">Surface:</label>
<input type="file" name="file" id="file"><br>
<input type="hidden" name="id" value="2">
<input type="hidden" name="map" value="surf">
<input type="submit" class="buttons" name="submit" value="Submit" onmouseover="butOn(this,true)" onmouseout="butOn(this,false)">
</form> <br><br>
The thing is that when the image is uploaded it gives me the "failed at re-sizing" thing so its the imagecopyresampled function that is failing. Also I checked the width and height vars by echo function and they are ok. The GD library is also working fine.