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

  • 写回答

2条回答 默认 最新

  • doujiao2014 2018-08-07 05:35
    关注

    You should use below code line before your code line $uploadOk = 1;

    move_uploaded_file($_FILES["upload"]["tmp_name"], $target_file);

    Like:

    if (move_uploaded_file($_FILES["upload"]["tmp_name"], $target_file)) {
        echo "The file ". basename( $_FILES["upload"]["name"]). " has been uploaded.";
    } else {
        echo "Sorry, there was an error uploading your file.";
    }
    

    While coping codes from some other sites please understand what is written in there and proceed. :-)

    $check = getimagesize($_FILES["upload"]["tmp_name"]); this line of code used to get size of image & do a size validation.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型