Advertisement

08.12.2005 at 03:47PM PDT, ID: 21525859
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

5.0

Follow on PHP & GD Question

Asked by JackHodson in PHP Scripting Language

Tags: , , ,

Hi, I have had some great help here creating a picture upload form with automatic resize, But I have come accross a problem - it does not seem to like huge pictures.

Here is the previous thread: http://www.experts-exchange.com/Web/Web_Languages/PHP/Q_21521973.html


When I was testing earlier I was only using 800x600 pics to test it, but now I am trying pictures that are about 1.5Mb + and a much higher res and I am getting this error:

Fatal error: Allowed memory size of 8388608 bytes exhausted (tried to allocate 7768 bytes) in /home/httpd/vhosts/cloverleaf4.co.uk/httpdocs/upload.php on line 76

Also when I tried a 2.4Mb picture I got the error message that was built in to the code: There was an error uploading the file, please try again!

Any ideas? I have adapted the code slightly, nothing major - just the text that users see, heres the latest:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Upload A File</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<?
     if($_SERVER['REQUEST_METHOD']!='POST') {
?>
<form action="<? echo $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data" name="form1">
  <table width="350" style="background-color:#F6F6F6;border:1px solid black;" border="0" cellspacing="2" cellpadding="2">
    <tr>
      <td style="font-weight:bold;background-color:#DDD;">Upload a file </td>
    </tr>
    <tr>
      <td style="text-align:center"><input name="file" type="file" size="30"></td>
    </tr>
    <tr>
      <td style="text-align:center"><input type="submit" name="Submit" value="Upload"></td>
    </tr>
  </table>
</form>
<?
} else {
     $message = "";
     $validExtensions[] = "jpg";
     $validExtensions[] = "jpeg";
      $validExtensions[] = "gif";
      $validExtensions[] = "png";

     $sentFileSize = ceil($_FILES['file']['size']/1024);
      # this way is more accurate for the extension
     $sentFileExtension = explode(".", $_FILES['file']['name']);
      $number = count($sentFileExtension);
      $sentFileExtension = $sentFileExtension[$number-1];

      if(!in_array($sentFileExtension, $validExtensions)) {
           $message = "Your file has <span style=\"color:red\">NOT</span> been uploaded,";
           $message .= " because of a bad extension. We only accept JPG and BMP files.";
      } else {
           // SAVE THE FILE
           $uploaddir = 'images/uploads/';
           if (file_exists('uploadCount.txt')) {
                $handle = fopen('uploadCount.txt','r+');
                $newFileNumber = fread($handle,filesize('uploadCount.txt'))+1;
                fclose($handle);
                $handle = fopen('uploadCount.txt','w');
                fwrite($handle,$newFileNumber.'');
                fclose($handle);
           } else {
                $handle = fopen('uploadCount.txt','x');
                fwrite($handle,'1');
                $newFileNumber = 1;
           }
           $uploadfile = $uploaddir . basename($newFileNumber . "." . $sentFileExtension);
             
             
                $bron = $_FILES['file']['tmp_name'];
                $maxbreedte = 640;
                }
               
                if(!empty($bron)){
                     $dimensies = getimagesize($bron);
                     $breedte = $dimensies[0];
                     $hoogte = $dimensies[1];
                     if($breedte > $maxbreedte){
                          $nieuwebreedte = $maxbreedte;
                          $deelfactor = $breedte / $maxbreedte;
                          $nieuwehoogte = $hoogte / $deelfactor;
           
                          switch ($dimensies['mime']) {
           
                          case 'image/jpeg':
           
                               $image = imagecreatefromjpeg($bron);
                               $destination = imagecreatetruecolor($nieuwebreedte, $nieuwehoogte);
                               imagecopyresampled($destination, $image, 0, 0, 0, 0, $nieuwebreedte, $nieuwehoogte, $breedte, $hoogte);
                               imagejpeg($destination, $uploadfile);
                              imagedestroy($image);
                              imagedestroy($destination);
                          break;
           
                          case 'image/gif':
           
                               $image = imagecreatefromgif($bron);
                               $destination = imagecreate($nieuwebreedte, $nieuwehoogte);
                               imagecopyresampled($destination, $image, 0, 0, 0, 0, $nieuwebreedte, $nieuwehoogte, $breedte, $hoogte);
                               imagegif($destination, $uploadfile);
                              imagedestroy($image);
                              imagedestroy($destination);
                          break;
                         
                          case 'image/png':
                         
                               $image = imagecreatefrompng($bron);
                               $destination = imagecreate($nieuwebreedte, $nieuwehoogte);
                               imagecopyresampled($destination, $image, 0, 0, 0, 0, $nieuwebreedte, $nieuwehoogte, $breedte, $hoogte);
                               imagepng($destination, $uploadfile);
                              imagedestroy($image);
                              imagedestroy($destination);
                          break;
                          }
                     } else {
                          $uploadfile = $uploaddir . basename($newFileNumber. "." .$sentFileExtension);
                          if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
                               $message = "Your file has been successfully uploaded.<br>";          
                               $message .= "Link to your file: [img]".$uploadfile."[/img]";
                          } else {
                               $message = "There was an error uploading the file, please try again!";
                          }
                     }
                }
           if (is_file($uploadfile)) {
                $message = "Your file has been successfully uploaded.<br>";          
                $message .= "Link to your file, copy bold text to display picture in forum: <b>[img]http://www.cloverleaf4.co.uk/".$uploadfile."[/img]</b>";
           } else {
                $message = "There was an error uploading the file, please try again!";
           }
?>
<table width="350" style="background-color:#F6F6F6;border:1px solid black;" border="0" cellspacing="2" cellpadding="2">
  <tr>
    <td style="font-weight:bold;background-color:#DDD;">File upload result </td>
  </tr>
  <tr>
    <td style="text-align:center"><? echo $message ?></td>
  </tr>
</table>
<?
}
?>
</body>
</html>

Thanks for any help solving the error :)
JackStart Free Trial
[+][-]08.12.2005 at 04:43PM PDT, ID: 14665497

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]08.12.2005 at 05:28PM PDT, ID: 14665673

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.12.2005 at 07:11PM PDT, ID: 14666273

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.13.2005 at 03:06AM PDT, ID: 14667160

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.13.2005 at 05:42AM PDT, ID: 14667336

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.14.2005 at 03:41AM PDT, ID: 14669981

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.14.2005 at 03:43AM PDT, ID: 14669986

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.14.2005 at 02:06PM PDT, ID: 14671469

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.14.2005 at 03:52PM PDT, ID: 14671711

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.14.2005 at 11:41PM PDT, ID: 14672708

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.15.2005 at 01:41AM PDT, ID: 14673075

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.15.2005 at 08:40AM PDT, ID: 14675311

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.15.2005 at 08:57AM PDT, ID: 14675449

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.15.2005 at 09:27AM PDT, ID: 14675695

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.15.2005 at 06:02PM PDT, ID: 14679454

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.15.2005 at 11:45PM PDT, ID: 14680613

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]08.16.2005 at 01:28AM PDT, ID: 14680896

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]08.16.2005 at 01:34AM PDT, ID: 14680927

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zone: PHP Scripting Language
Tags: memory, exhausted, allowed, php
Sign Up Now!
Solution Provided By: php-webdesign
Participating Experts: 2
Solution Grade: A
 
 
[+][-]08.16.2005 at 01:48AM PDT, ID: 14680980

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32