【问题标题】:PHP form with images upload带图片上传的 PHP 表单
【发布时间】:2011-01-03 11:51:14
【问题描述】:

我怎样才能做一个 php 和 xhtml 表单,允许用户上传图像并在提交时将所有数据发送到我的电子邮件?

【问题讨论】:

  • 给我密码?请更具体地说明您在处理文件上传的哪些部分遇到问题。

标签: php email forms image upload


【解决方案1】:

通过在 Google 上搜索教程并自己学习。这是一个太宽泛的问题,无法在本网站上发布。自己尝试一下,如果你能想出一个你没有答案的特定问题,请在这里提问。下面是一些帮助您入门的内容:

【讨论】:

    【解决方案2】:

    PHP 主站点本身也包含一些关于推荐做法和陷阱的有用信息,以及一些示例代码 - 请参阅“Handling file uploads”部分。

    【讨论】:

      【解决方案3】:

      试试这个

      <?
      //print_r($_POST);
      
      if($_POST["action"] == "Upload Image")
      {
      unset($imagename);
      
      if(!isset($_FILES) && isset($HTTP_POST_FILES))
      $_FILES = $HTTP_POST_FILES;
      
      if(!isset($_FILES['image_file']))
      $error["image_file"] = "An image was not found.";
      
      
      $imagename = basename($_FILES['image_file']['name']);
      //echo $imagename;
      
      if(empty($imagename))
      $error["imagename"] = "The name of the image was not found.";
      
      if(empty($error))
      {
      $newimage = "images/" . $imagename;
      //echo $newimage;
      $result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage);
      if(empty($result))
      $error["result"] = "There was an error moving the uploaded file.";
      }
      
      }
      
      ?>
      
      
      <form method="POST" enctype="multipart/form-data" name="image_upload_form" action="<?$_SERVER["PHP_SELF"];?>">
      <p><input type="file" name="image_file" size="20"></p>
      <p><input type="submit" value="Upload Image" name="action"></p>
      </form>
      
      <?
      if(is_array($error))
      {
      while(list($key, $val) = each($error))
      {
      echo $val;
      echo "<br>\n";
      }
      }
      ?>
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2014-05-19
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2018-09-11
        • 1970-01-01
        相关资源
        最近更新 更多