2011-03-02 114 views
0

我有这样的脚本:库文件上传问题PHP的

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); 
     } 

它正常工作与小图片,但如果我用更大的图片它仅适用于2个文件。如果我附加了3个或更多文件,则会上传它们,当页面刷新时,希望看到上传的图片,页面上没有任何内容。它返回到默认状态。甚至不显示错误消息。我将php5.ini upload_max_filesize重新配置为100M,但仍然没有任何内容。我使用php5文件扩展名,并且safe_mode被关闭到使用CGI模式的php5,并且gd2处于活动状态。可能是什么问题呢?

+0

可能重复[在PHP中上传最大大小?](http://stackoverflow.com/questions/3263480/upload-max-size-in-php) – 2011-03-02 11:54:38

+0

@Col。弹片你是什么意思。我已经在php5.ini中声明了代码 – Victor 2011-03-02 12:24:12

+0

中没有最大尺寸语句,但在链接的答案中有几个** PHP设置。你试过吗? – 2011-03-02 12:26:03

回答

-1

我想知道你的脚本是否超时?添加ini_set(“max_execution_time”,500);或什么东西到脚本的顶部,看看是否有帮助

+0

我已经把第一行后的第一行 为($ p = 0; $ p <$ num; $ p ++){ ini_set(“ max_execution_time“,500); 相同的结果 – Victor 2011-03-02 11:46:59

+0

您可能需要在脚本的第一行 – Alex 2011-03-02 11:55:48