douzhi6365 2013-09-07 16:19
浏览 201
已采纳

echo file_get_contents($ _ FILES [“image”] [“tmp_name”]不执行任何操作

I have written the following code. Nothing is written in the web browser and no error is thrown. Can anyone please help me to identify the problem?

try {
   echo file_get_contents($_FILES["image"]["tmp_name"]);
} catch (Exception $e) {
    echo 'Caught exception: ',  $e->getMessage(), "
";
}

Here is the form:

echo "<form action='upload.php' method='post' enctype='multipart/form-data'> 
        <p><input type='file' name='myfile'/></p>
        <p><input type='submit' value='Upload'/></p>
        </form>";

The thing was that I was following a tutorial where I was supposed to set: $image=file_get_contents($_FILES["image"]["tmp_name"]); When the person in the tutorial tried to echo it the files content was written in the browser. Nothing happened for me. I assume it is not working.

  • 写回答

1条回答 默认 最新

  • dongshanni1611 2013-09-07 16:32
    关注

    use

      file_get_contents($_FILES["myfile"]["tmp_name"]); 
    

    instead of

      file_get_contents($_FILES["image"]["tmp_name"]);
    

    since <input type='file' name='myfile'/>

    better ref from Changing the file name of a tmp file uploaded through a form

    if($_SERVER['REQUEST_METHOD']=='POST' && isset($username) && is_numeric($id)
    && isset($_FILES['myfile']['error']) && $_FILES['myfile']['error']=='UPLOAD_ERR_OK')
    {
        $name    = basename($_FILES['myfile']['name']);
        $ext     = end(explode('.', $name));
        $info    = getimagesize($_FILES['myfile']['tmp_name']);
    
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 win10权限管理,限制普通用户使用删除功能
  • ¥15 minnio内存占用过大,内存没被回收(Windows环境)
  • ¥65 抖音咸鱼付款链接转码支付宝
  • ¥15 ubuntu22.04上安装ursim-3.15.8.106339遇到的问题
  • ¥15 求螺旋焊缝的图像处理
  • ¥15 blast算法(相关搜索:数据库)
  • ¥15 请问有人会紧聚焦相关的matlab知识嘛?
  • ¥15 网络通信安全解决方案
  • ¥50 yalmip+Gurobi
  • ¥20 win10修改放大文本以及缩放与布局后蓝屏无法正常进入桌面