emvy03 Posted August 13, 2011 Share Posted August 13, 2011 Hi, I've got an upload script which works fine; it checks for image extension and uploads perfectly. The only thing is, I want to add an image resize section of code in there as I have an image gallery which displays the pictures and they are rather large. The code at present <link rel="stylesheet" href="upload.css" type="text/css" /> <?php define ("MAX_SIZE","100"); function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } $errors=0; if(isset($_POST['Submit'])) { $image=$_FILES['image']['name']; //if it is not empty if ($image) { $filename = stripslashes($_FILES['image']['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { //print error message echo '<h1>Unknown extension!</h1>'; $errors=1; } else { $size=filesize($_FILES['image']['tmp_name']); if ($size > MAX_SIZE*1024) { echo '<h1>You have exceeded the size limit!</h1>'; $errors=1; } $image_name=time().'.'.$extension; $gallery_name = $_POST['galleryselect']; $newname="../gallery/$gallery_name/".$image_name; $copied = copy($_FILES['image']['tmp_name'], $newname); if (!$copied) { echo '<h1>Copy unsuccessfull!</h1>'; $errors=1; }}}} if(isset($_POST['Submit']) && !$errors) { echo "<h1>File Uploaded Successfully! Try again!</h1>"; } include "../storescripts/connect_to_mysql.php"; $sql = mysql_query("INSERT into images (image_path, gallery_name) VALUES ('$newname',$gallery_name')"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/244686-upload-image-and-resize/ Share on other sites More sharing options...
jcbones Posted August 13, 2011 Share Posted August 13, 2011 The simplest way is to use the simpleImage class available from white-hat. It is free, and works well. The fastest way, is to use imageMajik, but not all servers have that installed. SimpleImage ImageMajik Quote Link to comment https://forums.phpfreaks.com/topic/244686-upload-image-and-resize/#findComment-1256833 Share on other sites More sharing options...
emvy03 Posted August 14, 2011 Author Share Posted August 14, 2011 Hi, Thanks for the help. Might sound like a daft question but in the line: $image->output(); How would I configure it to output the file to a directory. Is it is as simple as just putting the directory in there? Quote Link to comment https://forums.phpfreaks.com/topic/244686-upload-image-and-resize/#findComment-1257156 Share on other sites More sharing options...
voip03 Posted August 14, 2011 Share Posted August 14, 2011 move_uploaded_file($_FILES["file"]["tmp_name"], http://www.w3schools.com/php/php_file_upload.asp Quote Link to comment https://forums.phpfreaks.com/topic/244686-upload-image-and-resize/#findComment-1257158 Share on other sites More sharing options...
PFMaBiSmAd Posted August 14, 2011 Share Posted August 14, 2011 The examples at the link that jcbones posted, clearly show how to save the image vs outputting the image. Quote Link to comment https://forums.phpfreaks.com/topic/244686-upload-image-and-resize/#findComment-1257160 Share on other sites More sharing options...
emvy03 Posted August 14, 2011 Author Share Posted August 14, 2011 Hello, Yes, I was just wondering where to write the directory to output to, is it in between the output brackets? Quote Link to comment https://forums.phpfreaks.com/topic/244686-upload-image-and-resize/#findComment-1257171 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.