litebearer Posted March 18, 2012 Share Posted March 18, 2012 take a look at this (it will help you understand how to use functions) http://www.tizag.com/phpT/phpfunctions.php Quote Link to comment https://forums.phpfreaks.com/topic/259023-manipulating-uploaded-images/page/2/#findComment-1328872 Share on other sites More sharing options...
andy_b_1502 Posted March 18, 2012 Author Share Posted March 18, 2012 Yeah that did make things a bit clearer, after properly calling the Resize_Image function according to the link i get this: Fatal error: Cannot redeclare resize_image() (previously declared in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php:45) in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 why does it want to redeclare it? Quote Link to comment https://forums.phpfreaks.com/topic/259023-manipulating-uploaded-images/page/2/#findComment-1328873 Share on other sites More sharing options...
litebearer Posted March 19, 2012 Share Posted March 19, 2012 It means you are trying to define/create the function more than once (NOTE: define/create once, use many times) Show the most recent upload code in total Quote Link to comment https://forums.phpfreaks.com/topic/259023-manipulating-uploaded-images/page/2/#findComment-1328916 Share on other sites More sharing options...
andy_b_1502 Posted March 19, 2012 Author Share Posted March 19, 2012 <a href="index.php">Click here to go back to the homepage </a> <?php error_reporting(E_ALL); ini_set("display_errors", 1); echo '<pre>' . print_r($_FILES, true) . '</pre>'; //This is the directory where images will be saved $target = "/home/users/web/b109/ipg.removalspacecom/images/COMPANIES"; $target = $target . basename( $_FILES['upload']['name']); //This gets all the other information from the form $company_name=$_POST['company_name']; $basicpackage_description=$_POST['basicpackage_description']; $location=$_POST['location']; $postcode=$_POST['postcode']; $upload=($_FILES['upload']['name']); // Connects to your Database mysql_connect("", "", "") or die(mysql_error()) ; mysql_select_db("") or die(mysql_error()) ; //Writes the information to the database mysql_query("INSERT INTO `Companies` (company_name, basicpackage_description, location, postcode, upload) VALUES ('$company_name', '$basicpackage_description', '$location', '$postcode', '$upload')") ; echo mysql_error(); $uploadDir = 'images/COMPANIES'; // main picture folder $max_height = 450; // largest height you allowed; 0 means any $max_width = 450; // largest width you allowed; 0 means any $max_file = 2000000; // set the max file size in bytes $image_overwrite = 1; // 0 means overwite; 1 means new name $allowed_type01 = array( "image/gif", "image/pjpeg", "image/jpeg", "image/png", "image/x-png", "image/jpg"); // add or delete allowed image types $do_thumb = 1; // 1 make thumbnails; 0 means do NOT make $thumbDir = "/images/thumbs"; // thumbnail folder $thumb_prefix = ""; // prefix for thumbnails $thumb_width = 90; // max thumb width $thumb_height = 70; // max thumb height $do_shadow = 0; // 0 to add drop shadow to main image. 1 do NOT $flat_file = 0; // 1 flat file for data; 0 database $what_error = array(); // error message array/* // RESIZE FUNCTION */ function Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path) { $s_path = trim("/images/thumbs"); $o_path = trim("images/COMPANIES"); $save = $upload . $save; $file = $upload . $file; $ext = strtolower(end(explode('.',$save))); list($width, $height) = getimagesize($file) ; if(($width>$t_w) OR ($height>$t_h)) { $r1 = $t_w/$width; $r2 = $t_h/$height; if($r1<$r2) { $size = $t_w/$width; } else{ $size = $t_h/$height; } } else{ $size=1; } $modwidth = $width * $size; $modheight = $height * $size; $tn = imagecreatetruecolor($modwidth, $modheight) ; switch ($ext) { case 'jpg': case 'jpeg': $image = imagecreatefromjpeg($file) ; break; case 'gif': $image = imagecreatefromgif($file) ; break; case 'png': $image = imagecreatefrompng($file) ; break; } imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ; imagejpeg($tn, $save, 100) ; return;} /* END OF RESIZE FUNCTION */ //Writes the photo to the server if(move_uploaded_file($_FILES['upload']['tmp_name'], $target)) { /* CALL THE FUNCTION HERE */ function Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path) { "$save, $file, $t_w, $t_h, $s_path, $o_path"; } //Tells you if its all ok echo "The file ". basename( $_FILES['upload']['name']). " has been uploaded, and your information has been added to the directory"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/259023-manipulating-uploaded-images/page/2/#findComment-1328955 Share on other sites More sharing options...
andy_b_1502 Posted March 19, 2012 Author Share Posted March 19, 2012 I just changed the call function bit to this: <?php /* CALL THE FUNCTION HERE */ call_user_func($Resize_Image($save,$file,$t_w,$t_h,$s_path,$o_path)); { } ?> It did get rid of a lot of error messages but i have two left that need elliminating: Notice: Undefined variable: Resize_Image in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 Fatal error: Function name must be a string in /hermes/bosweb25a/b109/ipg.removalspacecom/basicpackage-send.php on line 86 Quote Link to comment https://forums.phpfreaks.com/topic/259023-manipulating-uploaded-images/page/2/#findComment-1328957 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.