Go Back   Web Hosting UK Forums | Linux Windows Dedicated Server and cPanel VPS Hosting Forum > Support > php issues.

Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 10-15-2007, 04:04 PM
Banned
 
Join Date: Oct 2007
Posts: 11
Cool [PHP] Simple Image Upload

PHP Code:
<?php

if (isset($_POST["submit"]))
 {
  
$uploadpath "Images/";
  
$uploadpath $uploadpath.basename($_FILES["imgfile"]["name"]);
  if (!
move_uploaded_file($_FILES["imgfile"]["tmp_name"], $uploadpath))
   die(
"There was an error uploading the file, please try again!");
  
$image_name "Images/".$_FILES["imgfile"]["name"];
  list(
$width,$height) = getimagesize($image_name);
  
$new_image_name "Images/thumb_".$_FILES["imgfile"]["name"];
  if (
$width $height)
   {
    
$ratio = (250/$width);
    
$new_width round($width*$ratio);
    
$new_height round($height*$ratio);
   }
  else
   {
    
$ratio = (250/$height);
    
$new_width round($width*$ratio);
    
$new_height round($height*$ratio);
   }
  
$image_p imagecreatetruecolor($new_width,$new_height);
$img_ext $_FILES['imgfile']['type'];
if (
img_ext == "image/jpg" || img_ext == "image/jpeg") {
$image imagecreatefromjpg($image_name);
} else if (
$img_ext == "image/png") {
$image imagecreatefrompng($image_name);
} else if (
$img_ext == "image/gif") {
$image imagecreatefromgif($image_name);
} else {
die(
'this is no valid image resource');
}

imagecopyresampled($image_p,$image,0,0,0,0,$new_width,$new_height,$width,$height);
imagejpeg($image_p,$new_image_name,100);
   echo(
"Image uploaded!");
 }

echo <<<TEXT
<form method="post" enctype="multipart/form-data">
<h1>Image Uploading</h1>
Please select a picture to upload:<br />
<input type="file" name="imgfile" />
<br />
<input type="submit" name="submit" value="Add Image" />
</form>
TEXT;

?>
Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 04:02 AM.
Copyright 2002-2007 WebHosting.uk.com. All rights reserved.
Web Hosting UK Forum