28, May 2012

resizing/uploading doesnt work with large-dimensioned images - webmaster forum

 
Webdigity webmaster forums
[ Home | Help | Search | Forum's Shop | Archive | Login | Register | Webmaster Directory ]
Webdigity Webmaster Forums  >  Web Development  >  PhP  >  PHP classes @finalwebsites.com  >  Easy PHP Upload (Moderator: Olaf)
Topic: resizing/uploading doesnt work with large-dimensioned images
« previous next »
Pages: [1] Print
Instabuck - The easy way to sell digital products online

Author Topic: resizing/uploading doesnt work with large-dimensioned images  (Read 3763 times)
Bill Cosby is my Father
*
Posts: 4
28 credits
Members referred : 0


« on: May 26, 2006, 08:17:50 pm »

First of wanted to say that you have created a great  product.

I am having some problems with the image resizing feature (foto_upload.php). Evevry time i upload a file it says that uploaded and processed. But i dont see the file(s) in my directory. Interesting thing is when i upload really small images like 150x100 it uploads. But as soon as i use bigger images nothing happens. Can you please help me?

Thanks!!
I am a metal monkey!
Administrator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 5799
46391 credits
Members referred : 3



« Reply #1 on: May 26, 2006, 08:21:23 pm »

I am not familliar with Olaf's classes, but this could be a problem of your php.ini (max_post_size)

Trial and Error my two best teachers Cool
Join us @ facebook or twitter

Last blog : Butterfly Marketing 2.0
Bill Cosby is my Father
*
Posts: 4
28 credits
Members referred : 0


« Reply #2 on: May 26, 2006, 08:25:01 pm »

Nikolas,

The max size in my php.ini is upto 4MB. And in any case, it should still throw me an error of "The uploaded file exceeds the max. upload filesize directive in the server configuration."

My files ar all around 1MB.
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #3 on: May 26, 2006, 09:11:34 pm »

Nikolas,

The max size in my php.ini is upto 4MB. And in any case, it should still throw me an error of "The uploaded file exceeds the max. upload filesize directive in the server configuration."

My files ar all around 1MB.
hello,

do you have a link to the upload form you're using? and place a phpinfo file on the host where the upload doesn't work.

Bill Cosby is my Father
*
Posts: 4
28 credits
Members referred : 0


« Reply #4 on: May 26, 2006, 10:07:23 pm »

Hi Olaf,

I am not entirely sure what you mean but I am just using this to repost to the same page.

<form enctype="multipart/form-data" method="post" action='.$_SERVER["PHP_SELF"];echo '?id='.$id; ...................

Let me know if you wanted to know something else.
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #5 on: May 26, 2006, 10:42:39 pm »

I need to see the whole form and your php cofiguration...

Bill Cosby is my Father
*
Posts: 4
28 credits
Members referred : 0


« Reply #6 on: May 26, 2006, 10:55:53 pm »

Ok..heres the code...the top portion is all your code...except where i change the file paths. let me know if any Q's:


<?php //require_once ('../includes/config.inc') ?>
<?php require_once ("../../mysql_connect.php") ?>
<?php include ("../includes/customer_header.html") ?>
<?php include ("../includes/upload_class.php") ?>

<?php if(isset($_SESSION["username"]))
{
// Check for a valid user ID, through GET or POST.
if ( (isset($_GET['id'])) && (is_numeric($_GET['id'])) ) { // Accessed through view_users.php
     $id = $_GET['id'];
} elseif ( (isset($_POST['id'])) && (is_numeric($_POST['id'])) ) { // Form has been submitted.
     $id = $_POST['id'];
} else { // No valid ID, kill the script.
     echo '<h1 id="mainhead">Page Error</h1>
     <p class="error">This page has been accessed in error.</p><p><br /><br /></p>';
     include ('../includes/customer_footer.html');
     exit();
}
error_reporting(E_ALL);
ini_set("memory_limit", "64M");
set_time_limit(60);

class Foto_upload extends file_upload {
   
   var $x_size;
   var $y_size;
   var $x_max_size = 300;
   var $y_max_size = 200;
   var $x_max_thumb_size = 110;
   var $y_max_thumb_size = 88;
   var $thumb_folder;
   var $foto_folder;
   var $larger_dim;
   var $larger_curr_value;
   var $larger_dim_value;
   var $larger_dim_thumb_value;
   
   var $use_image_magick = true; // switch between true and false
   // I suggest to use ImageMagick on Linux/UNIX systems, it works on windows too, but it's hard to configurate
   // check your existing configuration by your web hosting provider
   
   function process_image($landscape_only = false, $create_thumb = false, $delete_tmp_file = false, $compression = 85) {
      $filename = $this->upload_dir.$this->file_copy;
      $this->check_dir($this->thumb_folder); // run these checks to create not existing directories
      $this->check_dir($this->foto_folder); // the upload dir is created during the file upload (if not already exists)
      $thumb = $this->thumb_folder.$this->file_copy;
      $foto = $this->foto_folder.$this->file_copy;
      if ($landscape_only) {
         $this->get_img_size($filename);
         if ($this->y_size > $this->x_size) {
            $this->img_rotate($filename, $compression);
         }
      }
      $this->check_dimensions($filename); // check which size is longer then the max value
      if ($this->larger_curr_value > $this->larger_dim_value) {
         $this->thumbs($filename, $foto, $this->larger_dim_value, $compression);
      } else {
         copy($filename, $foto);
      }
      if ($create_thumb) {
         if ($this->larger_curr_value > $this->larger_dim_thumb_value) {
            $this->thumbs($filename, $thumb, $this->larger_dim_thumb_value, $compression); // finally resize the image
         } else {
            copy($filename, $thumb);
         }
      }
      if ($delete_tmp_file) $this->del_temp_file($filename); // note if you delete the tmp file the check if a file exists will not work
   }
   function get_img_size($file) {
      $img_size = getimagesize($file);
      $this->x_size = $img_size[0];
      $this->y_size = $img_size[1];
   }
   function check_dimensions($filename) {
      $this->get_img_size($filename);
      $x_check = $this->x_size - $this->x_max_size;
      $y_check = $this->y_size - $this->y_max_size;
      if ($x_check < $y_check) {
         $this->larger_dim = "y";
         $this->larger_curr_value = $this->y_size;
         $this->larger_dim_value = $this->y_max_size;
         $this->larger_dim_thumb_value = $this->y_max_thumb_size;
      } else {
         $this->larger_dim = "x";
         $this->larger_curr_value = $this->x_size;
         $this->larger_dim_value = $this->x_max_size;
         $this->larger_dim_thumb_value = $this->x_max_thumb_size;
      }
   }
   function img_rotate($wr_file, $comp) {
      $new_x = $this->y_size;
      $new_y = $this->x_size;
      if ($this->use_image_magick) {
         exec(sprintf("mogrify -rotate 90 -quality %d %s", $comp, $wr_file));
      } else {
         $src_img = imagecreatefromjpeg($wr_file);
         $rot_img = imagerotate($src_img, 90, 0);
         $new_img = imagecreatetruecolor($new_x, $new_y);
         imageantialias($new_img, TRUE);
         imagecopyresampled($new_img, $rot_img, 0, 0, 0, 0, $new_x, $new_y, $new_x, $new_y);
         imagejpeg($new_img, $this->upload_dir.$this->file_copy, $comp);
      }
   }
   function thumbs($file_name_src, $file_name_dest, $target_size, $quality = 80) {
      //print_r(func_get_args());
      $size = getimagesize($file_name_src);
      if ($this->larger_dim == "x") {
         $w = number_format($target_size, 0, ',', '');
         $h = number_format(($size[1]/$size[0])*$target_size,0,',','');
      } else {
         $h = number_format($target_size, 0, ',', '');
         $w = number_format(($size[0]/$size[1])*$target_size,0,',','');
      }
      if ($this->use_image_magick) {
         exec(sprintf("convert %s -resize %dx%d -quality %d %s", $file_name_src, $w, $h, $quality, $file_name_dest));
      } else {
         $dest = imagecreatetruecolor($w, $h);
         imageantialias($dest, TRUE);
         $src = imagecreatefromjpeg($file_name_src);
         imagecopyresampled($dest, $src, 0, 0, 0, 0, $w, $h, $size[0], $size[1]);
         imagejpeg($dest, $file_name_dest, $quality);
      }
   }
}

$max_size = 1024*1024; // the max. size for uploading (~1MB)
define("MAX_SIZE", $max_size);
$foto_upload = new Foto_upload;

$foto_upload->upload_dir = $_SERVER['DOCUMENT_ROOT']."/mysite/customers/uploads/"; // "files" is the folder for the uploaded files (you have to create these folder)
$foto_upload->foto_folder = $_SERVER['DOCUMENT_ROOT']."/mysite/customers/uploads/photo/";
$foto_upload->thumb_folder = $_SERVER['DOCUMENT_ROOT']."/mysite/customers/uploads/thumb/";
$foto_upload->extensions = array(".jpg"); // specify the allowed extension(s) here
$foto_upload->language = "en";
$foto_upload->x_max_size = 300;
$foto_upload->y_max_size = 200;
$foto_upload->x_max_thumb_size = 120;
$foto_upload->y_max_thumb_size = 150;
      
if (isset($_POST['Submit']) && $_POST['Submit'] == "Upload") {
   $foto_upload->the_temp_file = $_FILES['upload']['tmp_name'];
   $foto_upload->the_file = $_FILES['upload']['name'];
   $foto_upload->http_error = $_FILES['upload']['error'];
   $foto_upload->replace = (isset($_POST['replace'])) ? $_POST['replace'] : "n"; // because only a checked checkboxes is true
   $foto_upload->do_filename_check = "n";
   if ($foto_upload->upload()) {
      $foto_upload->process_image(false, true, true, 80);
      $foto_upload->message[] = "Processed foto: ".$foto_upload->file_copy."!"; // "file_copy is the name of the foto"
   }
}
$error = $foto_upload->show_error_string();

echo ' <table border="0" width="100%" cellspacing="0" cellpadding="0">
   <tr>
      <td valign="top" width="370"><a href="index.php">Home</a> » <a href="view_photo_listings.php">View Photo Listings</a> » <span class="content">Add Photos</span></td>
      <td valign="top">
      <p align="right"><span class="content">You are logged in as: <b>'.$_SESSION["username"];
echo '</b></span></td>
   </tr>
</table>
            <p align="center">'. $error; echo '</p>

            <div align="center">
               <table border="0" width="70%" cellspacing="0" cellpadding="0">
                  <tr>
                     <td valign="top" align="right"></td>
                  </tr>
               </table>
            </div>
            <form enctype="multipart/form-data" method="post" action='.$_SERVER["PHP_SELF"];echo '?id='.$id;
            echo '>
            <input type="hidden" name="MAX_FILE_SIZE" value="'. $max_size;
            echo' "><br>
            <div align="center">
               <table class="inputform" borderColor="#f0f0f0" border="1">
            <div>
              <label for="upload">Select a foto</label>
            <input type="file" name="upload" id="upload" size="30"></div>
             <div>
               <label for="replace">Replace an old foto?</label>
             <input type="checkbox" name="replace" value="y"></div>
            <p style="margin-top:25px;text-align:center;">
            <div align="center">
               <table cellSpacing="0" cellPadding="0" width="70%" border="0">
                  <tr>
                     <td width="100%">
                        <p align="center"><BR><input type="submit" name="Submit" id="Submit" value="Upload">
                           </p>
                     </td>
                  </tr>
               </table>
               </form>
               </div> ';
            }
            else {
            header ("Location:  http://" . $_SERVER['HTTP_HOST'] . "/mysite" . "/login.php");
      }
?>
<?php include_once("../includes/customer_footer.html") ?>
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #7 on: May 27, 2006, 09:46:40 am »

Wink that was too much...

The max filesize value in your form is 1MB (1024*1024)

Bill Cosby is my Father
*
Posts: 4
24 credits
Members referred : 0


« Reply #8 on: Jun 02, 2006, 03:35:16 pm »

I am actually having the same problem.  This script will only upload an image if it is within the specified file dimensions.  For example, I set my max to:
   var $x_max_size = 600;
   var $y_max_size = 500;
This script only successfully uploads images smaller than that (regardless of MB size)
My understanding is that the script should resize the file and put it in the appropriate folder.

It does say that it uploaded successfully, but the file is nowhere to be found on my server.
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #9 on: Jun 02, 2006, 03:42:50 pm »

I am actually having the same problem.  This script will only upload an image if it is within the specified file dimensions.  For example, I set my max to:
   var $x_max_size = 600;
   var $y_max_size = 500;
This script only successfully uploads images smaller than that (regardless of MB size)
My understanding is that the script should resize the file and put it in the appropriate folder.

It does say that it uploaded successfully, but the file is nowhere to be found on my server.

The upload and the resize are two diff. things (maybe the messages are not clear)
I will check the message, try to upload a file from 800KB and tell if the work fine.

Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #10 on: Jun 02, 2006, 04:58:39 pm »

Just checked the messages and the upload functions: everything is fine

maybe there are problems with the chmod values? it's a shared host?

Bill Cosby is my Father
*
Posts: 4
24 credits
Members referred : 0


« Reply #11 on: Jun 02, 2006, 06:17:35 pm »

It's a dedicated host, and all upload folders are chmod 777.

I just removed the dimension checking.  I just want to relay on actual filesize anyway.

Thanks
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #12 on: Jun 02, 2006, 11:08:31 pm »

I just want to relay on actual filesize anyway.


what do you mean with that? having max 1MB after Resize?

Bill Cosby is my Father
*
Posts: 4
24 credits
Members referred : 0


« Reply #13 on: Jun 02, 2006, 11:15:34 pm »

Yeah, I want it to check for file size in MB, the height and width is not as important, so in "process_image" I changed:

      $this->check_dimensions($filename); // check which size is longer then the max value
      if ($this->larger_curr_value > $this->larger_dim_value) {
         $this->thumbs($filename, $foto, $this->larger_dim_value, $compression);
      } else {
         copy($filename, $foto);
      }

to

      copy($filename, $foto);
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #14 on: Jun 03, 2006, 08:45:36 am »

you need only an upload functtion? check the regular example...

And don't change the source files otherwise you can't handle the updates later Wink

Bill Cosby is my Father
*
Posts: 4
24 credits
Members referred : 0


« Reply #15 on: Jun 03, 2006, 04:58:13 pm »

ok.  Thanks for being so insistant on helping me :-)
I love Pokemon
*
Posts: 13
90 credits
Members referred : 0


« Reply #16 on: Sep 25, 2006, 03:05:57 pm »

Hi, i'm having the exact same problem as one of your notice board users Olaf but the issue was never answered -

I am having some problems with the image resizing feature (foto_upload.php). Evevry time i upload a file it says that uploaded and processed. But i dont see the file(s) in my directory. Interesting thing is when i upload really small images like 150x100 it uploads. But as soon as i use bigger images nothing happens. I've increased the the 1Mb limit on the script upload file and the above issue seems to be resolved but i never get any errors!!!! - lke i thought too that with the foto script, that the images are resized for you aswell?


PLEASEEEEEEEEEEEEEEEE Can you please help me?

Thanks!!
Moderator
Community Supporter ?
Jedai Sword Master
*****
Gender: Male
Posts: 6691
34714 credits
Members referred : 374


It's time to use PHP5!


« Reply #17 on: Sep 25, 2006, 04:08:59 pm »

Hi, i'm having the exact same problem as one of your notice board users Olaf but the issue was never answered -

I am having some problems with the image resizing feature (foto_upload.php). Evevry time i upload a file it says that uploaded and processed. But i dont see the file(s) in my directory. Interesting thing is when i upload really small images like 150x100 it uploads. But as soon as i use bigger images nothing happens. I've increased the the 1Mb limit on the script upload file and the above issue seems to be resolved but i never get any errors!!!! - lke i thought too that with the foto script, that the images are resized for you aswell?


PLEASEEEEEEEEEEEEEEEE Can you please help me?

Thanks!!

of course the question was answered (I think you have diff. problem) thread closed -->

Trackback URI for this entry : http://www.webdigity.com/trackback.php?topic=2650
Tags : php hosting dedicated server php.ini Bookmark this thread : Digg Del.icio.us Dzone more....

Pages: [1] Print 
Webdigity Webmaster Forums  >  Web Development  >  PhP  >  PHP classes @finalwebsites.com  >  Easy PHP Upload (Moderator: Olaf)
Topic: resizing/uploading doesnt work with large-dimensioned images
« previous next »
Jump to:
User Area
Welcome, Guest. Please login or register.
Did you miss your activation email?
May 28, 2012, 10:24:15 am





Login with username, password and session length

Donate to our community, and get a permanent link back to your site!

Donate to our community, and get a permanent link back to your site!






Web Design Gallery · Whois Lookup · Pagerank · Tag Browsing · Lo-fi version · Syndication · Webmaster forum history · Advertise
Developed by HumanWorks © 2005 - 2012 Webdigity webmaster community · sublime directory
Webdigity Webmaster Forums | Powered by SMF 1.0.12. © 2001-2005, Lewis Media. All Rights Reserved.