duanou9758 2014-05-22 01:57
浏览 38
已采纳

在PHP中使用循环获取图像

I have selected multiple image and show the preview in a div box. When I click on Save button, I want to get the information of the image using loop in PHP.

I try to echo the image_path for testing purpose, but it show nothing output.

HTML Form

<form id="photo-event-form" name="event-photo-gallery-form" class="form-horizontal" method="post" role="form" enctype="multipart/form-data">
<fieldset>

   <div class="control-group">                                          
      <label class="control-label" for="event_date">Event Photo</label>
      <div class="controls">
       : <input type="file" class="span3" id="pg_album" name="pg_album" multiple />

          <div id="form_button_div" class="form_button_div">
          <button id="test" name="pg_Save" type="submit" class="btn btn-primary">Save</button> 
          <button class="btn">Cancel</button>
   </div>
</fieldset>
</form>

PHP Save submit

if (isset($_POST['pg_Save'])) {

    $image_path = $_FILES['pg_album'];

    $i = 0;
    foreach ($Contents as $image_path) {
        $i++;
        echo $image_path;  //display image file path
    }
}
?>
  • 写回答

1条回答 默认 最新

  • dqdfpmmi022763 2014-05-22 02:04
    关注

    In your foreach loop you are overwriting the value of $image_path. So if it had the right value (it doesn't) it is gone before you attempt to use it.

    Additionally, you cannot get the file path as it resided on the user's computer. That information is not provided and thus not available to you. If you want to know what information is available to you, read the PHP manual on handling file uploads.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 嵌入式系统基于PIC16F882和热敏电阻的数字温度计
  • ¥15 cmd cl 0x000007b
  • ¥20 BAPI_PR_CHANGE how to add account assignment information for service line
  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统