drj26159
2018-08-07 05:30
浏览 72
已采纳

图像文件上传无法在wamp服务器上运行

Here is my HTML code "post.html"

<!DOCTYPE html>
<html>
<body>

<form action="upload.php" method="post" enctype="multipart/form-data">
Select image to upload:
<input type="file" name="upload" id="upload">
<input type="submit" value="Upload Image" name="submit">
</form>

</body>
</html>

and here is my PHP code "upload.php"

<?php
target_dir = "upload/";
$target_file = $target_dir . basename($_FILES["upload"]["name"]);
$uploadOk = 1;
$imageFileType = strtolower(pathinfo($target_file,PATHINFO_EXTENSION));
// Check if image file is a actual image or fake image
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["upload"]["tmp_name"]);
if($check !== false) {
    echo "File is an image - " . $check["mime"] . ".";
    $uploadOk = 1;
} else {
    echo "File is not an image.";
    $uploadOk = 0;
}
}
?>

and the result I am getting is

File is an image - image/jpeg.

There is no issue with execution of the files but the thing is whenever I uploads any file or image via html code the file does not comes up in the upload folder despite of successful execution of the code.

P.S I am using php7 on wampserver

图片转代码服务由CSDN问答提供 功能建议

这是我的HTML代码 “post.html”

 <  code>&lt;!DOCTYPE html&gt; 
&lt; html&gt; 
&lt; body&gt; 
 
&lt; form action =“upload.php”method =“post”enctype =“multipart / form-data”&gt; 
选择图片 上传:
&lt; input type =“file”name =“upload”id =“upload”&gt; 
&lt; input type =“submit”value =“Upload Image”name =“submit”&gt; 
&lt; / 表单&gt; 
 
&lt; / body&gt; 
&lt; / html&gt; 
   
 
 

这是我的PHP代码“upload.php” &lt;?php target_dir =“upload /”; $ target_file = $ target_dir。 basename($ _ FILES [“upload”] [“name”]); $ uploadOk = 1; $ imageFileType = strtolower(pathinfo($ target_file,PATHINFO_EXTENSION)); //检查图像文件是否为实际 图像或假图像 if(isset($ _ POST [“submit”])){ $ check = getimagesize($ _ FILES [“upload”] [“tmp_name”]); if($ check!== false) { echo“文件是图像 - ”。 $ check [“mime”]。 “。”; $ uploadOk = 1; }其他{ echo“文件不是图像。”; $ uploadOk = 0; } } ?&gt;

我得到的结果是

 文件是图像 -  image / jpeg。
  <  / pre> 
 
 

执行文件没有问题,但事情是每当我通过html代码上传任何文件或图像时,尽管代码执行成功,文件仍未出现在上传文件夹中 。

PS我在wampserver上使用php7

  • 写回答
  • 好问题 提建议
  • 追加酬金
  • 关注问题
  • 邀请回答

2条回答 默认 最新

相关推荐 更多相似问题