【问题标题】:How to upload an image with html and php?如何使用 html 和 php 上传图片?
【发布时间】:2019-06-11 02:06:00
【问题描述】:

我正在尝试使用 html 和 php 上传图片,但是当我尝试时,它总是给我一个错误。

如果上传选项处于活动状态,我已经在 php.ini 文件中看到过,de max-size 也是 1000M

HTML 代码

<!DOCTYPE html>
<html lang="en">
<head>
  <title>Test</title>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
  <form action="php/uploadLocal.php" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload Image" name="submit">
  </form>
</body>
</html>

PHP 代码

<?php 
$target_dir = "images/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
if(isset($_POST["submit"])) {
  if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
      echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
  } else {
      echo "Sorry, there was an error uploading your file.";
  }
}
?>

【问题讨论】:

  • 你遇到了什么错误?

标签: php html image


【解决方案1】:

刚刚重启电脑,它工作,简直令人沮丧

【讨论】:

  • 你为什么给出这个答案?
  • @MohitKumar 这样其他人就不会浪费时间试图找到没有错误的地方
  • 你也必须把它放在评论中。
猜你喜欢
  • 2020-07-30
  • 1970-01-01
  • 2015-06-14
  • 2015-01-17
  • 2010-12-06
  • 2011-11-14
  • 2014-12-02
  • 2016-08-10
  • 1970-01-01
相关资源
最近更新 更多