dongwen1871 2014-02-20 03:22
浏览 41

php move_uploaded_file,移动时图像变为小红色x图标

I am trying to upload images and transfer them immediately to a specific folder.

Here's my code:

    $file_path = "assets/placervw_photo/";
    $file_path = $file_path . $_FILES['uploaded_file']['name'];
    if(move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $file_path))
    {
        echo "success";
    }

The page displays "success" but when I check the folder, it contains the file, having the same filename and file type, but it turns into a smal red X icon with white background. Here's a look: http://s14.postimg.org/ifoiyzde5/red_x.png

I have tested it to jpg and png files and they had the same outcome.

Any suggestions on how I can solve this? Thanks in advance! :)

  • 写回答

1条回答 默认 最新

  • dpmir1988 2014-02-20 03:28
    关注

    The "little red X" is your browser way of saying "There's no image here".

    Are you trying to display the image in the same page in which you upload it? You cannot. You already sent some content which is not image, so trying to signal the browser "I've got an image here" would get you a tiny red X.

    You need to send a IMG URL with the proper URL prefix:

    $url = "http://yourserver.com/path/to/".$file_path;
    
    echo "Success, here's your image: <img src=\"$url\" />";
    

    You'd probably also do well to not trust the user's file name, but assign a random ID of your choice, and also verify that it is indeed an image (you can use getImageSize(), also to verify the extension matches the MIME type). Just in case someone sends you a 'picture' called "../../../pwn3d.php": it's been known to happen.

    评论

报告相同问题?

悬赏问题

  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 基于卷积神经网络的声纹识别
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP