简体   繁体   English

画廊文件上传问题的PHP

[英]gallery file upload problem php

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. 它适用于小图片,但如果我使用大图片,则仅适用于2个文件。 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. 如果我附加3个或更多文件,它将上传它们,并且在刷新页面时,期望看到上传的图片页面上没有任何内容。 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. 我将php5.ini upload_max_filesize重新配置为100M,但仍然不进行任何操作。我使用php5文件扩展名,并且使用CGI模式将safe_mode关闭为php5,并且gd2处于活动状态。 What could be the problem? 可能是什么问题呢?

I wonder if your script is timing out? 我想知道您的脚本是否超时? Add ini_set("max_execution_time", 500); 添加ini_set(“ max_execution_time”,500); or something to the top of the script and see if that helps 或脚本顶部的内容,看看是否有帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM