douze2890241475 2018-04-21 16:45
浏览 24

使用PHP在使用表单上传的localhost上保存图像

i'm trying to save an image uploaded with a HTML form on my localhost server (working with Xampp), but although there are no errors, the file isn't saved anywhere. This is the form, really simple:

<form id="form1" action="result.php" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="imguploaded" id="imguploaded" accept=".png, .jpg, .jpeg"></br>
    <input class="btn btn-outline-danger btn-lg" id="inputbtn" type="submit" value="Upload Image" name="submit">
  </form>

and this is the PHP code (on result.php):

<?php
    $result=false;
    $error=false;
    if (isset($_FILES['imguploaded'])){
        $nomefile = strtolower($_FILES['imguploaded']['name']);
        $path = "caricamenti/$nomefile";
        move_uploaded_file($_FILES['imguploaded']['name'], $path);
        echo($path);
    }
    ?>

the path exists and it is in the same folder of the .PHP files.

  • 写回答

2条回答 默认 最新

  • dongqiongjiong4740 2018-04-21 17:00
    关注

    In move_uploaded_file($_FILES['imguploaded']['name'], $path); the first parameter isn't correct. It should be the temporary path where php stored it intermediatly, which you find in $_FILE['imguploaded']['tmp_name']. So change that line to

    move_uploaded_file($_FILES['imguploaded']['tmp_name'], $path);
    

    relevant docs

    Be sure to:

    • sanitize filename & extention first
    • check for allowed mimetypes, size, ..

    Right now I could easily upload a php script and execute that.

    评论

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?