2012-11-19 27 views
1

我一直在研究客戶端的管理面板(一家攝影公司將圖片上傳到客戶端的圖庫),當我擔任web開發人員時,允許他上傳30張圖片,即使有100個文件上傳框。這只是通過更改for循環來運行100次來解決。這解決了這個問題。在管理部分的PHP圖片上傳只允許客戶端上傳19張圖片

但最近,甚至沒有觸及代碼,我的客戶端只能上傳19圖像 ..我沒有改變這種形式,他以前上傳過40多張圖片,所以我不太明白什麼可以有發生..我已經檢查了一遍又一遍的代碼,似乎無法查明問題。這可能是服務器端,因爲我最近從他的老開發人員的主機移到我的東道主帳戶。也許在htaccess的東西?我想補充這一點,因爲圖像標籤的更新,但不是圖像本身我找不到它上傳或者,它已經發布後,但我的瀏覽器顯示它上傳

這裏是編輯畫廊代碼本身,如果它給這個問題的任何幫助:

<?php 
require_once("../conn.php"); 
require_once("access.php"); 
require_once("GalleryNavigation.php"); 
require_once("dThumbMaker.inc.php"); 

/////////////common varilable 
$__table = "devbg_gallery"; 
$__page = $_SERVER['PHP_SELF']; 
$__page2 = "AddGallery.php"; 
$__id = "ItemID"; 
$__pagetitle = "GALLERY"; 
$__uploadfolder = "../myimages/"; 
$__thumbuploadfolder = "../myimages/thumbs/"; 
$__imageprefix = "Gallery"; 
$Thumb_Imgwidth = 200; 
$Thumb_Imgheight = 77; 
///////////// 
if(isset($_POST[ds])) 
{ 
    if(count($_POST['DelItem']) > '0') 
    { 
     while(list(, $value) = each($_POST['DelItem'])) 
     { 
      $DelInfo = $value; 
      $r2 = mysql_query("select * from ".$__table." where ".$__id." = '$DelInfo' ") or die(mysql_error()); 
      $a2 = mysql_fetch_array($r2); 

      for($i=1;$i<=100;$i++) 
      { 
       if(file_exists($__uploadfolder.$a2['ItemImage'.$i])) 
       { 
        unlink($__uploadfolder.$a2['ItemImage'.$i]); 
        unlink($__thumbuploadfolder.$a2['ItemImage'.$i]); 
       } 
      } 

      //delete the product 
      mysql_query("delete from ".$__table." where ".$__id." = '".$DelInfo."' ") or die(mysql_error()); 
     } 
    } 
} 

if(isset($_POST[s100])) 
{ 
    $MyProductName = mysql_escape_string(trim(stripslashes(strip_tags($_POST[ProductName])))); 
    $Description = mysql_escape_string(trim(strip_tags(stripslashes($_POST['Description'])))); 
    $Link = trim(strip_tags(stripslashes($_POST['Link']))); 
    $TopLabel = cleaninput($_POST['TopLabel'],"mres|he|tr"); 
    $status = $_POST['status']; 
    $NewTopLabelName = $TopLabel; 

    if(!empty($_FILES['TopImage']['name'])) 
    { 
     $NewTopImageName = $__imageprefix.$t.$_FILES['TopImage']['name']; 
     if(is_uploaded_file($_FILES['TopImage']['tmp_name'])) 
     { 
      move_uploaded_file($_FILES['TopImage']['tmp_name'], $__uploadfolder.$NewTopImageName); 
      $NewTopImageName = $NewTopImageName; 
      $NewTopLabelName = $TopLabel; 
      //lets make the thumb 
      $tm = new dThumbMaker; 
      $load = $tm->loadFile($__uploadfolder.$NewTopImageName); 
      if($load === true) 
      { // Note three '=' 
       $tm->cropCenter($Thumb_Imgwidth, $Thumb_Imgheight); 
       $tm->build($__thumbuploadfolder.$NewTopImageName); 
      } 
      else 
      { 
       // Error returned. 
       $error .= "Could not open the file '".$NewTopImageName."'.\n"; 
       $error .= "The error returned was: "; 
       $error .= $load; 
      } 
     } 
    } 
    else 
    { 
     $NewTopImageName = $_POST['OldTopImage']; 
     $NewTopLabelName = $NewTopLabelName; 
    } 

    for($i=1;$i<=100;$i++) //This is where I believe the problem is -------------------------------------------------------------------- 
    { 
     ${'NewsItemLabel'.$i} = cleaninput($_POST['ItemLabel'.$i],"mres|he|tr"); 
     $ItemLabels .= "ItemLabel".$i ." = '". cleaninput($_POST['ItemLabel'.$i],"mres|he|tr") ."',"; 
     if(!empty($_FILES['ItemImage'.$i]['name'])) 
     { 
      ${'NewImageName'.$i} = $__imageprefix.$t.$_FILES['ItemImage'.$i]['name']; 
      if(is_uploaded_file($_FILES['ItemImage'.$i]['tmp_name'])) 
      { 
       move_uploaded_file($_FILES['ItemImage'.$i]['tmp_name'], $__uploadfolder.${'NewImageName'.$i}); 
       //lets make the thumb 
       $tm = new dThumbMaker; 
       $load = $tm->loadFile($__uploadfolder.${'NewImageName'.$i}); 
       if($load === true) 
       { // Note three '=' 
        $tm->cropCenter($Thumb_Imgwidth, $Thumb_Imgheight); 
        $tm->build($__thumbuploadfolder.${'NewImageName'.$i}); 
        $ItemImages .= "ItemImage".$i ." = '". ${'NewImageName'.$i} ."',"; 
       } 
       else 
       { 
        // Error returned. 
        $error .= "Could not open the file '".${'NewImageName'.$i}."'.\n"; 
        $error .= "The error returned was: "; 
        $error .= $load; 
       } 
      } else { } 
     } 
     else 
     { 
      ${'NewImageName'.$i} = $_POST['OldItemImage'.$i]; 
     } 
    } 

    if(empty($error)) 
    { 
     //update the database 
     $q1 = "update ".$__table." set 
         ItemName = '".$MyProductName."', 
         Description = '".$Description."', 
         Link = '".$Link."', 
         TopImage = '$NewTopImageName', 
         Toplabel = '$NewTopLabelName', 
         ".$ItemImages.$ItemLabels." 
         status = '".$status."' 

         where ".$__id." = '".$_POST[$__id]."' "; 

     mysql_query($q1) or die(mysql_error()); 
     echo "<br><br><center>Gallery Updated</center>"; 
    } 
} 
if(!empty($_GET[$__id])) 
{ 
    $_POST[$__id] = $_GET[$__id]; 
} 
if(!empty($_POST[$__id])) 
{ 
    //get the product info 
    $r1 = mysql_query("select * from devbg_gallery where ".$__id." = '".$_POST[$__id]."' ") or die(mysql_error()); 
    $a1 = mysql_fetch_array($r1); 

    echo $error; 
?> 
<form method=post action=EditGallery.php enctype="multipart/form-data"> 
<table align=center width=740> 
<caption align=center><b>Gallery Name:</b></caption> 
<tr> 
    <td align='right'>Event Name:</td> 
    <td><input type=text class=input name="ProductName" value="<?php echo $a1['ItemName'];?>"></td> 
</tr> 
<TR> 
    <td align='right'>Description:</td> 
    <td><textarea name="Description"cols=60 rows=10><?php echo $a1['Description'];?></textarea></td> 
</TR> 
<?php 
if(!empty($a1['TopImage'])) 
{ 
    $v = $a1['TopImage']; 
    echo "<tr>"; 
     echo "<td></td><td><img src='".$__uploadfolder.$v."' width='72' border='0'><br><a href='DeleteImage.php?".$__id."=".$a1[$__id]."&Type=gallery&file=".$v."&img=top'>Delete Image</a></td>"; 
    echo "</tr>"; 
} 
?> 
<tr> 
    <td align='right'>Top Image:</td> 
    <td><input type=file name=TopImage></td> 
</tr> 
<tr> 
    <td align='right'>Top Image Label:</td> 
    <td><input type=text name=TopLabel value="<?php echo $a1['TopLabel'];?>"></td> 
</tr> 
<?php 
      for($i = 1; $i <= 100; $i++) 
      { 
       if($a1['ItemImage'.$i] != "") 
       { 
        echo "<tr>"; 
        echo "<td></td><td><img src='".$__uploadfolder.$a1['ItemImage'.$i]."' width='72' border='0'><br><a href='DeleteImage.php?".$__id."=".$a1[$__id]."&Type=gallery&file=".$a1['ItemImage'.$i]."&id=".$i."'>Delete Image</a></td>"; 
        echo "</tr>"; 
       } 

       echo "<TR><TD align='right'>Image $i: </TD><TD><input type=file name='ItemImage$i'></TD></TR>\n\t"; 
       echo "<TR><TD align='right'>Label $i: </td><TD><input type=text name='ItemLabel".$i."' value='".cleaninput($a1['ItemLabel'.$i],"ss|hd|tr")."' size='79'></TD></TR>\n\t"; 
       echo "<input type='hidden' name='OldImage$i' value='".$a1['ItemImage'.$i]."'>"; 
       echo "<input type='hidden' name='OldLabel$i' value='".cleaninput($a1['ItemLabel'.$i],"ss|hd|tr")."'>"; 
      } 
?> 
<tr> 
    <td></td> 
    <td> 
     <input type="hidden" name="OldTopImage" value="<?php echo $a1['TopImage'];?>"> 
     <input type="hidden" name="OldTopLabel" value="<?php echo $a1['TopLabel'];?>"> 
     <input type="hidden" name=<?php echo $__id;?> value="<?php echo $_POST[$__id];?>"> 
     <input type="submit" name="s100" value="Edit Gallery"> 
    </td> 
</tr> 
</form> 
<?php 
    exit(); 
} 
if(!empty($_GET[Start])) 
{ 
    $Start = $_GET[Start]; 
} 
else 
{ 
    $Start = '0'; 
} 

$ByPage = "10"; 

//get the products list 
$r1 = mysql_query("select * from devbg_gallery order by ordering_id ASC limit $Start,$ByPage") or die(mysql_error()); 
if(mysql_num_rows($r1) == '0') 
{ 
    echo "<center>You have no items at the database!</center>"; 
    exit(); 
} 
?> 
<form method=post> 
<table align=center width=500 cellspacing="0" cellpadding="3"> 
<tr style="background-color:#b5c3ce; color:white; font-family:verdana; font-size:11; font-weight:bold"> 
    <td>Title</td> 
    <td>User</td> 
    <td align='center'>Edit</td> 
    <td align='center'>Delete</td> 
</tr> 
<?php 
$col = "white"; 
$i=0; 
while($a1 = mysql_fetch_array($r1)) 
{ 
    $r2 = mysql_query("select * from tbl_register where GID = '".$a1['ItemID']."'") or die(mysql_error()); 
    $a2 = mysql_fetch_array($r2); 
    $name = $a2['firstname'] . " " . $a2['lastname']; 

    $i++; 
    if($col == "white") 
    { 
     $col = "#f3f6f8"; 
    } 
    else 
    { 
     $col = "white"; 
    } 

    echo "<tr bgcolor=$col> 
      <td>".$a1['ItemName']."</td> 
      <td>".$name."</td>"; 
    echo "<td align=center><input type=radio name='".$__id."' value='".$a1[$__id]."'></td> 
      <td align='center'><input type='checkbox' name='DelItem[]' value='".$a1[$__id]."'></td> 
      </tr>\n\n"; 

} 
    echo "<tr> 
      <td colspan=4 align=right><br>\n\t<input class=input type=submit name=ds value='Edit Selected'> <input type='submit' class='input' name='ds' value='Delete Selected'></td> 
      </tr> 
</table> 
</form>\n\n"; 

//build the "next" - "prev" navigatioin 
$qnav = "select * from ".$__table." order by ItemName "; 
$rnav = mysql_query($qnav) or die(mysql_error()); 
$rows = mysql_num_rows($rnav); 
     echo "<br><table align=center width=600>"; 
     echo "<td align=center><font face=verdana size=2> | "; 
     $pages = ceil($rows/$ByPage); 

     for($i = 0; $i <= ($pages); $i++) 
     { 
      $PageStart = $ByPage*$i; 
      $i2 = $i + 1; 
      if($PageStart == $Start) 
      { 
       $links[] = " <span class=bodybold>$i2</span>\n\t "; 
      } 
      elseif($PageStart < $rows) 
      { 
       $links[] = " <a class=bodybold href=EditGallery.php?Start=$PageStart>$i2</a>\n\t "; 
      } 
     } 
     $links2 = implode(" | ", $links); 
     echo $links2; 
     echo "| </td>"; 
     echo "</table><br>\n"; 
?> 
<?php include("footer.php");?> 

如果有我可以提供,這將有助於找到解決辦法的任何其他信息,我可以將它張貼直線上升。這個問題真的與我的頭腦混爲一談,我的客戶需要他的畫廊運行!讓我希望自己能夠自己編碼,並在他之前的開發人員之前到達那裏。謝謝大家!

+1

運行phpinfo()並檢查內存限制。嘗試使用.htacces文件將其設置爲128M。 –

+2

將能力從40+以上降低到19以上的圖像肯定會導致移動到另一臺服務器。但是,你的客戶上傳的尺寸是多少?有大量的大圖片可能會非常緩慢上傳,導致超時或停止服務器限制。你有什麼錯誤嗎?您應該查看PHP配置中的upload_max_filesize,post_max_size和max_input_time。您可以在php.ini,.htaccess或甚至腳本本身中設置這些參數 - 但取決於您的主機。 – jtheman

+0

嗯,我確定這與圖像大小或超時無關,因爲我已經嘗試上傳非常小的圖像,並且在一批19個圖像後上傳了一個額外的圖像,所以我知道它只是一個圖像上傳。這是什麼混淆了我,讓我覺得,這是一個真正的服務器問題?: 在以前已超過** 30圖像上傳**,我刪除了**圖像26 **,並試圖重新上傳一個不同的圖像,但它沒有奏效。我對** image 17 **也做了同樣的事情,但它工作。所以我有**不知道** ...任何人都可以看到我失蹤的東西? – matthewc

回答

3

我的一個朋友想通了,當我移動的主機,我max_file_uploads在我的php.ini中設置爲,那你在上面看到的代碼循環每個圖像,並試圖將其上傳,甚至如果沒有圖像,這就解釋了爲什麼即使我只嘗試自行上傳1,它也不會在19之後上傳。只是忽略了一個簡單的設置。

更改爲max_file_uploads = 100在我的ini中,現在一切正常,客戶端開心!