frank_solo Posted April 11, 2011 Share Posted April 11, 2011 I'm trying to use this script known as SimpleImage.php that can be found here <a href="http://www.white-hat-web-design.co.uk/articles/php-image-resizing.php">link</a> I'm trying to include what is on the bottom of the page to my existing script can anyone help me I've tried several ways but its not working. <?php session_start(); error_reporting(E_ALL); ini_set('display_errors','On'); //error_reporting(E_ALL); // image upload folder $image_folder = 'images/classified/'; // fieldnames in form $all_file_fields = array('image1', 'image2' ,'image3', 'image4'); // allowed filetypes $file_types = array('jpg','gif','png'); // max filesize 5mb $max_size = 5000000; //echo'<pre>';print_r($_FILES);exit; $time = time(); $count = 1; foreach($all_file_fields as $fieldname){ if($_FILES[$fieldname]['name'] != ''){ $type = substr($_FILES[$fieldname]['name'], -3, 3); // check filetype if(in_array(strtolower($type), $file_types)){ //check filesize if($_FILES[$fieldname]['size']>$max_size){ $error = "File too big. Max filesize is ".$max_size." MB"; }else{ // new filename $filename = str_replace(' ','',$myusername).'_'.$time.'_'.$count.'.'.$type; // move/upload file $target_path = $image_folder.basename($filename); move_uploaded_file($_FILES[$fieldname]['tmp_name'], $target_path); //save array with filenames $images[$count] = $image_folder.$filename; $count = $count+1; }//end if }else{ $error = "Please use jpg, gif, png files"; }//end if }//end if }//end foreach if($error != ''){ echo $error; }else{ /* -------------------------------------------------------------------------------------------------- SAVE TO DATABASE ------------------------------------------------------------------------------------ -------------------------------------------------------------------------------------------------- */ ?> Quote Link to comment https://forums.phpfreaks.com/topic/233421-how-do-i-include-a-resizing-script-to-my-existing-script/ Share on other sites More sharing options...
sadavied Posted April 11, 2011 Share Posted April 11, 2011 1) Save that code to a file named 'simple_image.php' (recommend in an 'includes' directory) 2) either include or require_once that file in the script you want to use it in 3) create an instance of the SimpleImage class 4) use the member functions of the class to resize the image Quote Link to comment https://forums.phpfreaks.com/topic/233421-how-do-i-include-a-resizing-script-to-my-existing-script/#findComment-1200310 Share on other sites More sharing options...
jcbones Posted April 12, 2011 Share Posted April 12, 2011 You are not very clear. You want to save the image to a database? You want to save the image path to a database? Does the image upload correctly? Does the script work except for the database entry? Quote Link to comment https://forums.phpfreaks.com/topic/233421-how-do-i-include-a-resizing-script-to-my-existing-script/#findComment-1200325 Share on other sites More sharing options...
frank_solo Posted April 12, 2011 Author Share Posted April 12, 2011 My script alone works corks correctly but I can't seem to find the correct way to include this include('SimpleImage.php'); $image = new SimpleImage(); $image->load($_FILES['uploaded_image']['tmp_name']); $image->resizeToWidth(150); $image->output(); into my script. My script uploads the image to a file directory, but I want to resize the image and then upload the image to the destination folder. Does anyone know how to write it in to script? Quote Link to comment https://forums.phpfreaks.com/topic/233421-how-do-i-include-a-resizing-script-to-my-existing-script/#findComment-1200327 Share on other sites More sharing options...
jcbones Posted April 12, 2011 Share Posted April 12, 2011 Try this: May not work the first time around cause it is UN-TESTED! <?php session_start(); error_reporting(E_ALL); ini_set('display_errors','On'); include('SimpleImage.php'); $image = new SimpleImage(); //error_reporting(E_ALL); // image upload folder $image_folder = 'images/classified/'; // fieldnames in form $all_file_fields = array('image1', 'image2' ,'image3', 'image4'); // allowed filetypes $file_types = array('jpg','gif','png'); // max filesize 5mb $max_size = 5000000; //echo'<pre>';print_r($_FILES);exit; $time = time(); $count = 1; foreach($all_file_fields as $fieldname){ if($_FILES[$fieldname]['name'] != ''){ $type = substr($_FILES[$fieldname]['name'], -3, 3); // check filetype if(in_array(strtolower($type), $file_types)){ //check filesize if($_FILES[$fieldname]['size']>$max_size){ $error = "File too big. Max filesize is ".$max_size." MB"; }else{ // new filename $filename = str_replace(' ','',$myusername).'_'.$time.'_'.$count.'.'.$type; // move/upload file $image->load($_FILES['uploaded_image']['tmp_name']); if($image->getWidth() > 150) { //if the image is larger that 150. $image->resizeToWidth(150); //resize to 150. } $target_path = $image_folder.basename($filename); //image path. $image->save($target_path); //save image to a directory. //save array with filenames $images[$count] = $image_folder.$filename; $count = $count+1; }//end if }else{ $error = "Please use jpg, gif, png files"; }//end if }//end if }//end foreach if($error != ''){ echo $error; }else{ /* -------------------------------------------------------------------------------------------------- SAVE TO DATABASE ------------------------------------------------------------------------------------ -------------------------------------------------------------------------------------------------- */ ?> Quote Link to comment https://forums.phpfreaks.com/topic/233421-how-do-i-include-a-resizing-script-to-my-existing-script/#findComment-1200332 Share on other sites More sharing options...
frank_solo Posted April 12, 2011 Author Share Posted April 12, 2011 The same happen to me Getting errors: Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in /../SimpleImage.php on line 28 Warning: imagesx(): supplied argument is not a valid Image resource in /../SimpleImage.php on line 60 Warning: imagejpeg(): supplied argument is not a valid Image resource in /../SimpleImage.php on line 40 Quote Link to comment https://forums.phpfreaks.com/topic/233421-how-do-i-include-a-resizing-script-to-my-existing-script/#findComment-1200334 Share on other sites More sharing options...
frank_solo Posted April 12, 2011 Author Share Posted April 12, 2011 Does anyone know what these errors mean? Quote Link to comment https://forums.phpfreaks.com/topic/233421-how-do-i-include-a-resizing-script-to-my-existing-script/#findComment-1200373 Share on other sites More sharing options...
dcro2 Posted April 12, 2011 Share Posted April 12, 2011 It means you didn't supply a filename (or a blank filename). The other two errors are because obviously you can't make an image out of nothing. Just change $image->load($_FILES['uploaded_image']['tmp_name']); to $image->load($_FILES[$fieldname]['tmp_name']); Quote Link to comment https://forums.phpfreaks.com/topic/233421-how-do-i-include-a-resizing-script-to-my-existing-script/#findComment-1200448 Share on other sites More sharing options...
frank_solo Posted April 12, 2011 Author Share Posted April 12, 2011 Dear dcro2, YOU ARE A GOD!!!!! Thanks everyone for the help! Quote Link to comment https://forums.phpfreaks.com/topic/233421-how-do-i-include-a-resizing-script-to-my-existing-script/#findComment-1200540 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.