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 sqlserver排序语句
  • ¥15 请看一下,学校实验要求,我需要具体代码
  • ¥50 pc微信3.6.0.18不能登陆 有偿解决问题
  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃