PHP GD image upload failing

Dear all,

I have a script written for me by a member here some while ago.
I am using it on a new website and when I try to upload a large photo it is failing and comes back blank - it does not say the upload failed, simply it comes back blank (the header and footer of the website comes back but anything within the PHP does not.

For small photos it works well and uploads it to the folder.

I have tried increasing the following using a .htaccess file:
memory_limit to 100MB
post_max_size to 100MB
upload_max_filesize to 100Mb

still it did not work. the defaults are now set again and they are:
memory_limit to 24MB
post_max_size to 8MB
upload_max_filesize to 10Mb.

The code is pasted below and the php settings are here:
http://arockes.org.uk/images/user_photo_uploads/php_info.php

The uploader web page is here: http://arockes.org.uk/photo_uploader.php

PHP is something that does not make a huge amount of sense to me so if you could shed any light on this I would really appreciate it.

Kind regards,
Jack
<br />
    <?
     if($_SERVER['REQUEST_METHOD']!='POST') {
?>
  </p>
  <p>  </p>
  <form action="<? echo $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data" name="Photo Uploader" id="Photo Uploader">
  <table width="375" style="background-color: #FFFFFF;border:1px solid; border-color:#DDDDDD;" border="0" cellspacing="2" cellpadding="2">
    <tr>
      <td width="365" style="font-weight:normal; color:#000000;background-color:#FFFFFF;">Upload your car or event photos here:</td>
    </tr>
    <tr>
      <td style="text-align:left"><input name="file" type="file" size="35" /></td>
    </tr>
    <tr>
      <td style="text-align:center"><input type="submit" name="Submit" value=":.Send.:" /></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 = strtolower($sentFileExtension[$number-1]);
 
      if(!in_array($sentFileExtension, $validExtensions)) {
           $message = "<span style=\"color:black; font size:11px\"><br>Your photo has <span style=\"color:red\">NOT</span> been uploaded,";
           $message .= " because of an invalid file type. <br>We only accept .JPG, .GIF and .PNG files.</span>";
      } else {
           // SAVE THE FILE
           $uploaddir = 'images/user_photo_uploads/';
           if (file_exists('images/photo_uploader_count.txt')) {
                $handle = fopen('images/photo_uploader_count.txt','r+');
                $newFileNumber = fread($handle,filesize('images/photo_uploader_count.txt'))+1;
                fclose($handle);
                $handle = fopen('images/photo_uploader_count.txt','w');
                fwrite($handle,$newFileNumber.'');
                fclose($handle);
           } else {
                $handle = fopen('images/photo_uploader_count.txt','x');
                fwrite($handle,'1');
                $newFileNumber = 1;
           }
           $uploadfile = $uploaddir . basename($newFileNumber . "." . $sentFileExtension);
 
 
                $bron = $_FILES['file']['tmp_name'];
                $maxbreedte = 1024;
                }
 
                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)) {
                               chmod($uploadfile, 0644);
                               $message = "Your photo has been saved successfully, to upload another, click Back and repeat.<br>";
                         
                          } else {
                               $message = "There was an error uploading the file, please try again!";
                          }
                     }
                }
           if (is_file($uploadfile)) {
                $message = "<span style=\"color:black; font size:11px\"><br>Your photo has been saved successfully, to upload<br>another, click your browsers back button and repeat.<br>";
 
           } else {
                $message .= "<span style=\"color:black; font size:11px\"><br><br>Please click your browsers back button to try again.";
           }
?>
<br /><table width="500" style="background-color:#FFFFFF;border:1px solid; border-color:#DDDDDD;" border="0" cellspacing="2" cellpadding="2">
  <tr>
    <td style="font-weight:normal; color:#000000;background-color:#FFFFFF;">Photo upload result:</td>
  </tr>
  <tr>
    <td style="text-align:center"><? echo $message ?></td>
  </tr>
</table>
<?
}
?>

Open in new window

LVL 4
JackIT ManagerAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

JagarmTechnical Support AnalystCommented:
Set those settings through PHP right before you do the upload stuff:

ini_set("upload_max_filesize","100");

do the same thing with the other ones

Let me know how it goes

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
JackIT ManagerAuthor Commented:
Forgive my ignorance but do you mean I should create a php.ini file with that code and upload it to the webspace?
Should it go in the httpdocs (root) of the site?
Should I remove the .htaccess file?
0
JagarmTechnical Support AnalystCommented:
You can simply change the setting right from your php file,

let say you have a file called. pictures.php

<?php

ini_set("upload_max_filesize","100");

//then you do the uploading stuff, as I think the upload happens in only one file ... right?

?>

Please let me know if this is unclear.

You must have other stuff in your .htaccess, but comment the line where it changes the settings.

0
Learn Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

JackIT ManagerAuthor Commented:
The .htaccess only has the following:
memory_limit to 24MB
post_max_size to 8MB
upload_max_filesize to 10Mb

so I will remove it.

I am a little unclear with your instructions. The entire page is below in the code snippet, I added the line you said at the beginning of the php.
Yes you are correct, it all happens in the one file.

Jack
<!--HTML-->
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/site_template.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Alfa Romeo Owners Club, Kent and East Sussex Section</title>
<!-- InstanceEndEditable -->
<link rel="stylesheet" href="css/site.css" type="text/css">
<link rel="stylesheet" href="css/lightbox.css" type="text/css"  media="screen">
<script type="text/javascript" src="Templates/js/prototype.js"></script>
<script type="text/javascript" src="Templates/js/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="Templates/js/lightbox.js"></script>
<!-- InstanceBeginEditable name="head" -->
 
 
<link href="css/site.css" rel="stylesheet" type="text/css" />
<!-- InstanceEndEditable -->
</head>
<body>
<div id="container">
<div id="header">
<div class="top_banner1">Alfa Romeo Owners Club, <br>Kent & East Sussex Section</div>
<div class="top_banner2"> <img src="images/alfa_romeo_script_with_logo.jpg" alt="Alfa script with logo" width="403" height="62"> </div>
<div class="layout1"> <a href="start.htm"><img src="images/home_button.gif" alt="Home Button" border="0"></a> <a href="news.htm"><img src="images/news_button.gif" alt="News Button" border="0"></a> <a href="aboutus.htm"><img src="images/about_us_button.gif" alt="About Us Button" border="0"></a> <a href="events_2009.htm"><img src="images/events-2009_button.gif" alt="Events 2009 Button" border="0"></a> <a href="past_events.htm"><img src="images/past_events_button.gif" alt="Past Events Button" border="0"></a> <a href="articles.htm"><img src="images/articles_button.gif" alt="Articles Button" border="0"></a></div>
<div class="layout2"> <img src="images/silver_line_1.gif" width="682" height="4"> </div>
</div>
<div class="next_meet"> Next monthly meeting: Thursday 31 July 2009 at <a href="../http://maps.google.co.uk/maps?f=d&source=s_d&saddr=51.305184,0.330995&daddr=A20%2FLondon+Rd&hl=en&geocode=%3BFTHbDgMd9gwFAA&mra=dme&mrcr=0&mrsp=0&sz=17&sll=51.30509,0.33187&sspn=0.003468,0.009613&ie=UTF8&ll=51.30509,0.33187&spn=0.013871,0.038452&z=15" target="_blank">The Moat, Wrotham</a></div>
<div class="content1"><!-- InstanceBeginEditable name="Content_Region1" -->
  <br /><?php
 
ini_set("upload_max_filesize","100");?>
    <?
     if($_SERVER['REQUEST_METHOD']!='POST') {
?>
  </p>
  <p>  </p>
  <form action="<? echo $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data" name="Photo Uploader" id="Photo Uploader">
  <table width="375" style="background-color: #FFFFFF;border:1px solid; border-color:#DDDDDD;" border="0" cellspacing="2" cellpadding="2">
    <tr>
      <td width="365" style="font-weight:normal; color:#000000;background-color:#FFFFFF;">Upload your car or event photos here:</td>
    </tr>
    <tr>
      <td style="text-align:left"><input name="file" type="file" size="35" /></td>
    </tr>
    <tr>
      <td style="text-align:center"><input type="submit" name="Submit" value=":.Send.:" /></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 = strtolower($sentFileExtension[$number-1]);
 
      if(!in_array($sentFileExtension, $validExtensions)) {
           $message = "<span style=\"color:black; font size:11px\"><br>Your photo has <span style=\"color:red\">NOT</span> been uploaded,";
           $message .= " because of an invalid file type. <br>We only accept .JPG, .GIF and .PNG files.</span>";
      } else {
           // SAVE THE FILE
           $uploaddir = 'images/user_photo_uploads/';
           if (file_exists('images/photo_uploader_count.txt')) {
                $handle = fopen('images/photo_uploader_count.txt','r+');
                $newFileNumber = fread($handle,filesize('images/photo_uploader_count.txt'))+1;
                fclose($handle);
                $handle = fopen('images/photo_uploader_count.txt','w');
                fwrite($handle,$newFileNumber.'');
                fclose($handle);
           } else {
                $handle = fopen('images/photo_uploader_count.txt','x');
                fwrite($handle,'1');
                $newFileNumber = 1;
           }
           $uploadfile = $uploaddir . basename($newFileNumber . "." . $sentFileExtension);
 
 
                $bron = $_FILES['file']['tmp_name'];
                $maxbreedte = 1024;
                }
 
                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)) {
                               chmod($uploadfile, 0644);
                               $message = "Your photo has been saved successfully, to upload another, click Back and repeat.<br>";
                         
                          } else {
                               $message = "There was an error uploading the file, please try again!";
                          }
                     }
                }
           if (is_file($uploadfile)) {
                $message = "<span style=\"color:black; font size:11px\"><br>Your photo has been saved successfully, to upload<br>another, click your browsers back button and repeat.<br>";
 
           } else {
                $message .= "<span style=\"color:black; font size:11px\"><br><br>Please click your browsers back button to try again.";
           }
?>
<br /><table width="500" style="background-color:#FFFFFF;border:1px solid; border-color:#DDDDDD;" border="0" cellspacing="2" cellpadding="2">
  <tr>
    <td style="font-weight:normal; color:#000000;background-color:#FFFFFF;">Photo upload result:</td>
  </tr>
  <tr>
    <td style="text-align:center"><? echo $message ?></td>
  </tr>
</table>
<?
}
?>
<!-- InstanceEndEditable --></div>
<div class="layout4"> <img src="images/silver_line_2.gif" width="682" height="4"></div>
<div class="layout3"> <a href="contactus.htm"><img src="images/contact_us_button.gif" alt="Contact Us Button" border="0"></a> <a href="links.htm"><img src="images/links_button.gif" alt="Links Button" border="0"></a> <a href="forsale.htm"><img src="images/for_sale_button.gif" alt="For Sale Button" border="0"></a> <a href="memberscars.htm"><img src="images/member_cars_button.gif" alt="Members Cars Button" border="0"></a> <a href="servicing.htm"><img src="images/servicing_button.gif" alt="Servicing Button" border="0"></a> <a href="search.htm"><img src="images/search_button.gif" alt="Search Button" border="0"></a></div>
</div>
 
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-367549-3");
pageTracker._trackPageview();
} catch(err) {}</script>
 
</body>
<!-- InstanceEnd --></html>

Open in new window

0
JagarmTechnical Support AnalystCommented:
How you have it now is how I instructed, and it is suppose to work, remove those lines from .htaccess to avoid confusions.

Please let me know how it goes.

Thanks
0
JagarmTechnical Support AnalystCommented:
Almost forgot, you should do the same thing with memory_limit, and post_max_size, simply put them right after or before (whoever you like) the ini_set("upload_max_filesize","100");
0
JackIT ManagerAuthor Commented:
OK, thanks, I will need to add the
memory_limit and post_max_size now.

Is it ok like this, I am not sure how they should be separated?:

<?php
 
ini_set("upload_max_filesize","100");
ini_set("memory_limit","100");
ini_set("post_max_size","100");
?>
    <?
     if($_SERVER['REQUEST_METHOD']!='POST') {
?>
0
Seo_ExpertCommented:
Hello Jack,

This may happened because you do not have right (permission) to override default .httaccess files.
Please contact your web hosting provider if you have to increase more limit.
0
JagarmTechnical Support AnalystCommented:
That is good how you have it.
0
JackIT ManagerAuthor Commented:
Hi Seo,

I did conntact them initially and they told me to create use an .htaccess file. If I make changes to this file it is immediately reflected in this: http://arockes.org.uk/images/user_photo_uploads/php_info.php

Appreciate the help guys, php makes css (which I have just begun with) look easy!
0
JackIT ManagerAuthor Commented:
Still not working im afraid.
Latest code below.
<!--HTML-->
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/site_template.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>Alfa Romeo Owners Club, Kent and East Sussex Section</title>
<!-- InstanceEndEditable -->
<link rel="stylesheet" href="css/site.css" type="text/css">
<link rel="stylesheet" href="css/lightbox.css" type="text/css"  media="screen">
<script type="text/javascript" src="Templates/js/prototype.js"></script>
<script type="text/javascript" src="Templates/js/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="Templates/js/lightbox.js"></script>
<!-- InstanceBeginEditable name="head" -->
 
 
<link href="css/site.css" rel="stylesheet" type="text/css" />
<!-- InstanceEndEditable -->
</head>
<body>
<div id="container">
<div id="header">
<div class="top_banner1">Alfa Romeo Owners Club, <br>Kent & East Sussex Section</div>
<div class="top_banner2"> <img src="images/alfa_romeo_script_with_logo.jpg" alt="Alfa script with logo" width="403" height="62"> </div>
<div class="layout1"> <a href="start.htm"><img src="images/home_button.gif" alt="Home Button" border="0"></a> <a href="news.htm"><img src="images/news_button.gif" alt="News Button" border="0"></a> <a href="aboutus.htm"><img src="images/about_us_button.gif" alt="About Us Button" border="0"></a> <a href="events_2009.htm"><img src="images/events-2009_button.gif" alt="Events 2009 Button" border="0"></a> <a href="past_events.htm"><img src="images/past_events_button.gif" alt="Past Events Button" border="0"></a> <a href="articles.htm"><img src="images/articles_button.gif" alt="Articles Button" border="0"></a></div>
<div class="layout2"> <img src="images/silver_line_1.gif" width="682" height="4"> </div>
</div>
<div class="next_meet"> Next monthly meeting: Thursday 31 July 2009 at <a href="../http://maps.google.co.uk/maps?f=d&source=s_d&saddr=51.305184,0.330995&daddr=A20%2FLondon+Rd&hl=en&geocode=%3BFTHbDgMd9gwFAA&mra=dme&mrcr=0&mrsp=0&sz=17&sll=51.30509,0.33187&sspn=0.003468,0.009613&ie=UTF8&ll=51.30509,0.33187&spn=0.013871,0.038452&z=15" target="_blank">The Moat, Wrotham</a></div>
<div class="content1"><!-- InstanceBeginEditable name="Content_Region1" -->
  <br /><?php
 
ini_set("upload_max_filesize","100");
ini_set("memory_limit","100");
ini_set("post_max_size","100");
?>
    <?
     if($_SERVER['REQUEST_METHOD']!='POST') {
?>
  </p>
  <p>  </p>
  <form action="<? echo $_SERVER['PHP_SELF'] ?>" method="post" enctype="multipart/form-data" name="Photo Uploader" id="Photo Uploader">
  <table width="375" style="background-color: #FFFFFF;border:1px solid; border-color:#DDDDDD;" border="0" cellspacing="2" cellpadding="2">
    <tr>
      <td width="365" style="font-weight:normal; color:#000000;background-color:#FFFFFF;">Upload your car or event photos here:</td>
    </tr>
    <tr>
      <td style="text-align:left"><input name="file" type="file" size="35" /></td>
    </tr>
    <tr>
      <td style="text-align:center"><input type="submit" name="Submit" value=":.Send.:" /></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 = strtolower($sentFileExtension[$number-1]);
 
      if(!in_array($sentFileExtension, $validExtensions)) {
           $message = "<span style=\"color:black; font size:11px\"><br>Your photo has <span style=\"color:red\">NOT</span> been uploaded,";
           $message .= " because of an invalid file type. <br>We only accept .JPG, .GIF and .PNG files.</span>";
      } else {
           // SAVE THE FILE
           $uploaddir = 'images/user_photo_uploads/';
           if (file_exists('images/photo_uploader_count.txt')) {
                $handle = fopen('images/photo_uploader_count.txt','r+');
                $newFileNumber = fread($handle,filesize('images/photo_uploader_count.txt'))+1;
                fclose($handle);
                $handle = fopen('images/photo_uploader_count.txt','w');
                fwrite($handle,$newFileNumber.'');
                fclose($handle);
           } else {
                $handle = fopen('images/photo_uploader_count.txt','x');
                fwrite($handle,'1');
                $newFileNumber = 1;
           }
           $uploadfile = $uploaddir . basename($newFileNumber . "." . $sentFileExtension);
 
 
                $bron = $_FILES['file']['tmp_name'];
                $maxbreedte = 1024;
                }
 
                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)) {
                               chmod($uploadfile, 0644);
                               $message = "Your photo has been saved successfully, to upload another, click Back and repeat.<br>";
                         
                          } else {
                               $message = "There was an error uploading the file, please try again!";
                          }
                     }
                }
           if (is_file($uploadfile)) {
                $message = "<span style=\"color:black; font size:11px\"><br>Your photo has been saved successfully, to upload<br>another, click your browsers back button and repeat.<br>";
 
           } else {
                $message .= "<span style=\"color:black; font size:11px\"><br><br>Please click your browsers back button to try again.";
           }
?>
<br /><table width="500" style="background-color:#FFFFFF;border:1px solid; border-color:#DDDDDD;" border="0" cellspacing="2" cellpadding="2">
  <tr>
    <td style="font-weight:normal; color:#000000;background-color:#FFFFFF;">Photo upload result:</td>
  </tr>
  <tr>
    <td style="text-align:center"><? echo $message ?></td>
  </tr>
</table>
<?
}
?>
<!-- InstanceEndEditable --></div>
<div class="layout4"> <img src="images/silver_line_2.gif" width="682" height="4"></div>
<div class="layout3"> <a href="contactus.htm"><img src="images/contact_us_button.gif" alt="Contact Us Button" border="0"></a> <a href="links.htm"><img src="images/links_button.gif" alt="Links Button" border="0"></a> <a href="forsale.htm"><img src="images/for_sale_button.gif" alt="For Sale Button" border="0"></a> <a href="memberscars.htm"><img src="images/member_cars_button.gif" alt="Members Cars Button" border="0"></a> <a href="servicing.htm"><img src="images/servicing_button.gif" alt="Servicing Button" border="0"></a> <a href="search.htm"><img src="images/search_button.gif" alt="Search Button" border="0"></a></div>
</div>
 
<script type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</script>
<script type="text/javascript">
try {
var pageTracker = _gat._getTracker("UA-367549-3");
pageTracker._trackPageview();
} catch(err) {}</script>
 
</body>
<!-- InstanceEnd --></html>

Open in new window

0
JagarmTechnical Support AnalystCommented:
There are certain php configurations that have limits on where they can be configured, so for upload_max_filesize is set to PHP_INI_PERDIR, which means it can either be set in php.ini, .htaccess or httpd.conf, that may be the reason it is not working.
0
JagarmTechnical Support AnalystCommented:
Put the following in your .htacess and let me know if it works, because it works for me.


RewriteEngine on
php_value upload_max_filesize 100M
php_value memory_limit 100MB
php_value post_max_size 100MB

Open in new window

0
JackIT ManagerAuthor Commented:
I have done that.

I created a separate test file for this:
http://www.arockes.org.uk/phototest.php

Its was not working for anything ..even tiny files, then I removed the following and it worked again for tiny files.

<?php
 
ini_set("upload_max_filesize","100");
ini_set("memory_limit","100");
ini_set("post_max_size","100");
?>
0
JackIT ManagerAuthor Commented:
http://www.arockes.org.uk/images/user_photo_uploads/php_info.php

The PHP info page now does NOT work for some reason.
0
JagarmTechnical Support AnalystCommented:
Do you have php_value in your .htaccess before setting any php settings?

Have you also contacted your host and let them know that is not working?
0
JackIT ManagerAuthor Commented:
In my .htaccess file, literally all there is, is this:

RewriteEngine on
php_value upload_max_filesize 100M
php_value memory_limit 100MB
php_value post_max_size 100MB

I have not told the host yet. I could but I thought it may be the code that is incorrect.
0
JagarmTechnical Support AnalystCommented:
Remove the MB beside the last two, that maybe why
0
JagarmTechnical Support AnalystCommented:
No sorry, either way should work: MB or M

For phpinfo page, check if there's any errors there, mistyping something, will not throw an error ... in my case at least
0
JagarmTechnical Support AnalystCommented:
Based on your phpinfo, the changes has been made, and they are all at 100Megabyte from the default. It should work, because the changes has been made
0
JackIT ManagerAuthor Commented:
This is strange. I changed the MB to Ms in the .htaccess - this fixed php_info. Good!

Then the upload was still not working so I put this back in:

<?php
 
ini_set("upload_max_filesize","100");
ini_set("memory_limit","100");
ini_set("post_max_size","100");
?>

This did not work, so I made the 100s in to "100M"s. I can now upload a 0.6MB photo. A 2.2MB still does not work and gives the blank page after a minute or so (slow upload).

Right, to try and solve this and thinking about it I do not really need the image resize and resample. Do you think it would work if we got rid of that aspect and simply made it a straight forward file uploader?

Many thanks again,
Jack
0
JagarmTechnical Support AnalystCommented:
Remove the following:

ini_set("upload_max_filesize","100");
ini_set("memory_limit","100");
ini_set("post_max_size","100");

because they are set in the .htaccess
0
JagarmTechnical Support AnalystCommented:
There are restrictions on where each setting can be set.

http://ca2.php.net/manual/en/ini.core.php
0
JagarmTechnical Support AnalystCommented:
While setting the memory limit to 100 megabyte, I was getting an error in one of my other scripts, just in case you get that, do the following:

php_value memory_limit -1

which is unlimited or increase the memory up more.
0
JackIT ManagerAuthor Commented:
Not getting anywhere with this unfortunately. Have tried uping the limits, also I read this in your link and made the changes:

  post_max_size  integer -  Sets max size of post data allowed. This setting also affects file upload. To upload large files, this value must be larger than upload_max_filesize. If memory limit is enabled by your configure script, memory_limit also affects file uploading. Generally speaking, memory_limit should be larger than post_max_size .

Still it didn't work. What do you think about removing the resize code and having it just as a straight forward upload?
Is it the resize of the images that is causing this?

Jack
0
JagarmTechnical Support AnalystCommented:
Your upload form may be missing something, do you have the following inside your upload form?

the following sets the max file size to 100 megabyte

<input type="hidden" name="MAX_FILE_SIZE" value="104857600" />
0
JackIT ManagerAuthor Commented:
Where should I put this line?

Thanks
0
JagarmTechnical Support AnalystCommented:
Anywhere inside the <form> </form> tag, this will be hidden, so it doesn't matter, put it at the very top right after the opening <form> tag
0
JackIT ManagerAuthor Commented:
Same result but thanks for your efforts and persistence.
0
JagarmTechnical Support AnalystCommented:
When do you get an error (if any)? and when it says "Your photo has been saved successfully" does it really uploads the file on the server into the provided directory?
0
JackIT ManagerAuthor Commented:
Basically if I upload a file that is more than about 800Kb it will start the upload and then after a bit the screen window will refresh completely blank - the photo will not be in the directory either. If its under about 800Kb then it works fine.
0
JagarmTechnical Support AnalystCommented:
Are you using this script: http://www.arockes.org.uk/phototest.php, I uploaded a jpeg of 952 KB and it worked through http://www.arockes.org.uk/phototest.php and I get the screen where it says upload was successful

0
JackIT ManagerAuthor Commented:
if you try a 3MB file, like that of straight from a new digital camera will it still upload for you?

I did manage to get a 1Mb file to upload too - it seems very picky.
Yes it is that script.
0
JagarmTechnical Support AnalystCommented:
I don't know about that, because I don't have a digital camera and haven't tried it, but I guess the only way to fail, is for the uploaded not to be able to read the file.

I guess the only way to be sure, is have a note on the site and tell them to move the image in the computer.

Have you tried uploading the 3mb from the digital camera?
0
JackIT ManagerAuthor Commented:
Yes, I have this script which is on a different host which has no problems with 5MB files.

www.cloverleaf4.co.uk/upload.php

I think I need to get on to the host and see if they can help.
0
JackIT ManagerAuthor Commented:
If you can, download this file and try it on the upload:
http://upload.wikimedia.org/wikipedia/en/7/7b/Space_Ship_2_Jan_2008.jpg
0
JagarmTechnical Support AnalystCommented:
Sure, it is currently downloading, I'll let you know the result, I will upload using http://www.arockes.org.uk/phototest.php
0
JagarmTechnical Support AnalystCommented:
I downloaded the image you provided and uploaded, and yes I got the blank screen. Please put this at the very top of that page: error_reporting(E_ALL); so it displays all the errors



0
JagarmTechnical Support AnalystCommented:
Are you also watermarking the images that are being uploaded?
0
JackIT ManagerAuthor Commented:
No watermarking on the photos. I think I need to give up with this for now. Just can not work it out. I added error_reporting(E_ALL) but it didnt give anything away at all when giving the blank page.

<?php
error_reporting(E_ALL);
?>
    <?
     if($_SERVER['REQUEST_METHOD']!='POST') {
?>

Is it ok inserted like this?
0
JagarmTechnical Support AnalystCommented:
If you look at your code in the question at the top, on line 55 there is             $maxbreedte = 1024; which I'm not sure what is that, it maybe maximum height or width.

Maybe that is what is giving problems
0
JackIT ManagerAuthor Commented:
Tried removing that but no joy. I will contact the host and let you know. Thanks.
0
JackIT ManagerAuthor Commented:
They are not sure on the problem either - they asked me to change some more limits in the htaccess file but still no joy. Time to give up unfortunately. Thanks for your attempts though.

Jack
0
JagarmTechnical Support AnalystCommented:
I'm sorry to hear that your host didn't do anything, I have PHP 5.2.10 installed on Apache 2 on Windows XP Sp2. The following is the content of the htaccess:

RewriteEngine on
php_value upload_max_filesize 100M
php_value memory_limit 100M
php_value post_max_size 100M

Using the original script in your question, allows me to upload any size pictures even the
http://upload.wikimedia.org/wikipedia/en/7/7b/Space_Ship_2_Jan_2008.jpg with no problem.

Could you please copy the original script into a file, just call it test.php and run it, and see if that works, and make sure to have .htaccess with the above content in it.

Let me know how it went,
0
JackIT ManagerAuthor Commented:
Can I ask, what upload speed is available to you from your ISP?

They thought it may be that my upload is very slow (0.3mbps). They also had no problems either but they have a big fat leased line.
0
JackIT ManagerAuthor Commented:
Also, does it matter where the .htaccess file is located on the webspace?
0
JagarmTechnical Support AnalystCommented:
Sorry I forgot to mention, but I ran it locally, on my computer
0
JagarmTechnical Support AnalystCommented:
I don't think it matters, as long as it is in the same subdomain, but to be on the safe side, just make an .htaccess in the same location as the script
0
JackIT ManagerAuthor Commented:
Hi, I will close this question. The script that was written for me some time ago that I referred to in the first line of my question worked unedited so there must be something vital that I removed.

Points awarded to Jagarm, very grateful for the effort you went to to try and help me solve this.

Thanks
Jack
0
JackIT ManagerAuthor Commented:
Not a solution but grateful for the efforts.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.