2015-12-14 53 views
1

我有一個多圖像上傳頁面。事情是當我更新previusoly上傳的圖像。這些上傳的圖片在數據庫上有自己的ID。所以,當我點擊更新POST時,並非所有圖像都沒有設置爲5。

Dump => array(1) { 
    ["editproductimages"] => array(5) { 
    ["name"] => array(5) { 
     [0] => string(0) "" 
     [1] => string(11) "desktop.jpg" 
     [2] => string(40) "12071419_404680519720527_756783084_n.jpg" 
     [3] => string(0) "" 
     [4] => string(0) "" 
    } 
    ["type"] => array(5) { 
     [0] => string(0) "" 
     [1] => string(10) "image/jpeg" 
     [2] => string(10) "image/jpeg" 
     [3] => string(0) "" 
     [4] => string(0) "" 
    } 
    ["tmp_name"] => array(5) { 
     [0] => string(0) "" 
     [1] => string(25) "/opt/lampp/temp/phpYJDIAO" 
     [2] => string(25) "/opt/lampp/temp/phpmyxoXB" 
     [3] => string(0) "" 
     [4] => string(0) "" 
    } 
    ["error"] => array(5) { 
     [0] => int(4) 
     [1] => int(0) 
     [2] => int(0) 
     [3] => int(4) 
     [4] => int(4) 
    } 
    ["size"] => array(5) { 
     [0] => int(0) 
     [1] => int(55203) 
     [2] => int(33773) 
     [3] => int(0) 
     [4] => int(0) 
    } 
    } 
} 

我想的事情是增加內部$ _FILE喜歡持有交thier數據庫ID提取物陣列領域。

["id"] => array(5) { 
      [0] => int(10) 
      [1] => int(11) 
      [2] => int(12) 
      [3] => int(14) 
      [4] => int(13) 
     } 

是可能的嗎?

謝謝!

+0

請張貼一些代碼 –

+0

您是否嘗試過使用每個圖像的ID提交隱藏輸入? – Armen

+0

我不認爲添加自定義字段到'$ _FILES'超全局是可能的....據我所知 – Andrew

回答

0

我不認爲這是正確的方法或正確的答案,但我認爲array_push可能會幫助你,因爲$ _FILES也是一個數組。

可以說這是文件數據。

$filesData = array(
     array('editproductimages'=>array(
       array("name"=>array("","desktop.jpg","12071419_404680519720527_756783084_n.jpg","","")), 
       array("type"=> array("","image/jpeg","image/jpeg","","")), 
       array("tmp_name"=>array("","/opt/lampp/temp/phpYJDIAO","/opt/lampp/temp/phpmyxoXB","","")), 
       array("error"=>array(4,0,0,4,4)), 
       array("size"=>array(0,55203,33773,0,0)) 
      )) 
    ); 

然後在下面的數組($ IDS)是你想成爲什麼樣added.You只需要使用array_push添加它。

$ids = array('id'=>array(10,11,12,14,13)); 
    //actual insertion of $ids to the $filesData variable 
    array_push($filesData[0]['editproductimages'],$ids); 
    echo '<pre>'; 
    var_dump($filesData); 
    echo '</pre>'; 

我希望幫助

+0

讓我看看,但我原來想修改$ FILE_本身的實現,以便我可以在後期映射所有的ID。 – danielad

+1

我不知道你爲什麼要重寫$ _FILE的實現,因爲我不知道你想實現什麼,我的建議是不重寫它。儘管你也可以爲你的ID添加一個輸入(隱藏),然後使用上面的代碼把它放在$ _FILE中。 –

0

你可以像這樣做,可以說你有這種形式

<form action=""> 
    <!-- For your first image --> 
    <input type="hidden" name="image_ids[]" value="<?php ..place first image id.. ?>" /> 
    <input type="file" name="image[]"/> 

    <!-- For your second image --> 
    <input type="hidden" name="image_ids[]" value="<?php ..place second image id.. ?>" /> 
    <input type="file" name="image[]"/> 

    <!-- For your third image --> 
    <input type="hidden" name="image_ids[]" value="<?php ..place third image id.. ?>" /> 
    <input type="file" name="image[]"/> 

    ..... 
</form> 

提交這份表格到PHP後,你將有價值觀的相同順序$_FILE['image']$_POST['image']陣列,你可以使循環

foreach($_POST['image_ids'] as $k => $id){ 
    // process and save $_FILE['image'][$k] 
    // use $id to save/update necessary values in db 
} 
相關問題