0

I have this script:

 if(($_POST['number2'] && !$_POST['button_add']) || ($_POST['number2'] && !$_POST['button_add_gal'])) { $num=$_POST['number2'];
            for($p=0; $p<$num; $p++) {
            if ($_POST['page']=='news') {
                        $dir = '../images/news/'; // Директорията в която ще се записват файловете
                        }
                        if ($_POST['page']=='gallery') {
                        $dir = '../images/gallery/'; // Директорията в която ще се записват файловете
                        }
                        $name[$p]='gal_'.$_FILES['file']['name'][$p];
                        move_uploaded_file($_FILES['file']['tmp_name'][$p], $dir.$name[$p]);
            $filename[$p] = $name[$p];



                        if ($_POST['page']=='news') {
                        createThumb('../images'.DIRECTORY_SEPARATOR.'news'.DIRECTORY_SEPARATOR.$filename[$p]);

                echo '<img src="../images/news/thumb_'.$filename[$p].'" width="50" height="50" border="0" style="margin-left:10px;">';
                        }
                        if ($_POST['page']=='gallery') {
                          createThumb('../images'.DIRECTORY_SEPARATOR.'gallery'.DIRECTORY_SEPARATOR.$filename[$p]);

                echo '<img src="../images/gallery/thumb_'.$filename[$p].'" width="50" height="50" border="0" style="margin-left:10px;">';

                 if($_POST['page']=='gallery'){
            resizeImage('../images'.DIRECTORY_SEPARATOR.'gallery'.DIRECTORY_SEPARATOR.$filename[$p]);   }
                        if ($_POST['page']=='news'){
                           resizeImage('../images'.DIRECTORY_SEPARATOR.'news'.DIRECTORY_SEPARATOR.$filename[$p]);
                        }
                        }
 } }  

 function createThumb($source, $thumb_width=150)
        {
     $fl = dirname($source);
     $new_name = 'thumb_'.basename($source);
     $img = imagecreatefromjpeg($source);
     $width = imagesx($img);
     $height = imagesy($img);
     $new_width = $thumb_width;
     $new_heght = floor($height * ($thumb_width / $width));
     $tmp_img = imagecreatetruecolor( $new_width, $new_heght );
     imagecopyresampled($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_heght, $width, $height);
      imagejpeg($tmp_img, $fl.DIRECTORY_SEPARATOR.$new_name);
        }

         function resizeImage($source, $thumb_width=700)
        {
     $fl = dirname($source);
     $new_name = basename($source);
     $img = imagecreatefromjpeg($source);
     $width = imagesx($img);
     $height = imagesy($img);
     $new_width = $thumb_width;
     $new_heght = floor($height * ($thumb_width / $width));
     $tmp_img = imagecreatetruecolor( $new_width, $new_heght );
     imagecopyresampled($tmp_img, $img, 0, 0, 0, 0, $new_width, $new_heght, $width, $height);
      imagejpeg($tmp_img, $fl.DIRECTORY_SEPARATOR.$new_name);
        }

It works fine with small pictures but if I use bigger pictures it works only for 2 files. If I attach 3 or more files it upload them and when the page is refreshed, expecting to see the uploaded pictures there is nothing on the page. It's returned into default state. Not even an error message is displayed. I reconfigured the php5.ini upload_max_filesize to 100M but still nothing.I use php5 file extensions and safe_mode is switched off to php5 with CGI mode and gd2 is active. What could be the problem?

HaskellElephant
  • 9,819
  • 4
  • 38
  • 67
Victor
  • 99
  • 1
  • 6
  • 15
  • possible duplicate of [Upload max size in PHP?](http://stackoverflow.com/questions/3263480/upload-max-size-in-php) – Your Common Sense Mar 02 '11 at 11:54
  • @Col. Shrapnel what do you mean. I've declare it in a php5.ini there is no max size statements in the code – Victor Mar 02 '11 at 12:24
  • there are **several** PHP settings in the answer by the link. dud you try them all? – Your Common Sense Mar 02 '11 at 12:26
  • I've putted the ini_set after in the first if before the for loop, in the for loop, before the firts if and beacause this included page in the firt line of the page where this script is included. Any other suggestions where to put it elsewhere because I don't have in mind. – Victor Mar 02 '11 at 12:29
  • you can't control PHP upload from php script, as upload being done BEFORE your script is called. you have to alter these settings in php.ini/.htaccess – Your Common Sense Mar 02 '11 at 13:48

1 Answers1

-1

I wonder if your script is timing out? Add ini_set("max_execution_time", 500); or something to the top of the script and see if that helps

Alex
  • 7,320
  • 1
  • 18
  • 31
  • I've putted the line in the first line after the first for for($p=0; $p<$num; $p++) { ini_set("max_execution_time", 500); same result – Victor Mar 02 '11 at 11:46
  • You probably want it in the very first line of your script – Alex Mar 02 '11 at 11:55