Upload and Resize an Image with PHP - php Form

Author Topic: Upload and Resize an Image with PHP  (Read 844 times)

Offline alex

  • Global Moderator
  • *****
  • Posts: 77
  • Karma: +19/-0
    • View Profile
Upload and Resize an Image with PHP
« on: May 10, 2010, 04:55:32 AM »


Code: [Select]
<?php
if(isset($_POST['Submit']))
{
$current_image=$_FILES['image']['name'];
$extension substr(strrchr($current_image, ), 1);
if ((
$extension!= "jpg") && ($extension != "jpeg"))  
{
die(
'Unknown extension');
}
$time date("fYhis");
$new_image $time "." $extension;
$destination="uploads/".$new_image;
$action copy($_FILES['image']['tmp_name'], $destination);

if (!
$action
{
die(
'File copy failed');
}else{
echo 
"File copy successful";
}

//resize//

$create imagecreatefromjpeg($destination);
$currwidth imagesx($create); 
$currheight imagesy($create);
$ccreate ImageCreateTrueColor(50,50);

imagecopyresampled($ccreate$create00005050
$currwidth$currheight); 
imagejpeg($ccreate"thumbs/".$new_image);
imagedestroy($ccreate); 
imagedestroy($create); 

}else{
?>

<form method="post" enctype="multipart/form-data" action="submit.php">
<input type="file" name="image" ><br>
<input type="submit" name="Submit" value="submit">
</form>
<?php
}
?>