gallery file upload problem php

110 views Asked by At

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?

1

There are 1 answers

2
Alex On

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