dongmi1941 2014-06-26 19:49
浏览 28
已采纳

用PHP轻松上传文件[关闭]

I have tried this tutorial : http://www.tutorialspoint.com/php/php_file_uploading.htm

And no success :(

I do not understand the point where this guy states

The following example below attempts to copy a file uploaded by the HTML Form listed in previous section page to /var/www/html directory which is document root of your PHP server

I tried using the filesystem path to the php script : I:\xampp\htdocs\tester\ (normally the .php is here) and it wouldn't work.

I get this error :

Warning: copy(stock-footage-hand-presses-a-confidential-stamp-contains-matte.jpg) [function.copy]: failed to open stream: No such file or directory in I:\xampp\htdocs\tester\uploader.php on line 4

Could not copy file!

I do not understand what i am doing wrong, and if you could give me a little example, i would greatly appreciate.

  • 写回答

1条回答 默认 最新

  • douliang1900 2014-06-26 20:07
    关注
    <?php
    if(isset($_REQUEST["uploadnow"]))
    {
        $directory  = "images/";    //directory name where the image should get stored
        $imageDet   = $_FILES["uploadfile"];
        if($imageDet["name"]!="")
        {
            //source as tmpname and destination as destination directory
            copy($imageDet["tmp_name"],$directory.$imageDet["name"]);
        }
    }
    ?>
    
    <form method="post" enctype="multipart/form-data">
        <input type="file" name="uploadfile" />
        <input type="submit" value="Upload Now" name="uploadnow" />
    </form>
    

    Hope the above code would be helpful. and note that the directory (the destination directory) has to be present for uploading. Note : method="post" and enctype="multipart/form-data" is must when you upload a file from form.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。
  • ¥15 opencv图像处理,需要四个处理结果图
  • ¥15 无线移动边缘计算系统中的系统模型
  • ¥15 深度学习中的画图问题
  • ¥15 java报错:使用mybatis plus查询一个只返回一条数据的sql,却报错返回了1000多条
  • ¥15 Python报错怎么解决
  • ¥15 simulink如何调用DLL文件