dongmi1941 2014-06-26 11: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 12: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 KeiI中头文件找不到怎么解决
  • ¥15 QT6将音频采样数据转PCM
  • ¥15 本地安装org.Hs.eg.dby一直这样的图片报错如何解决?
  • ¥15 下面三个文件分别是OFDM波形的数据,我的思路公式和我写的成像算法代码,有没有人能帮我改一改,如何解决?
  • ¥15 Ubuntu打开gazebo模型调不出来,如何解决?
  • ¥100 有chang请一位会arm和dsp的朋友解读一个工程
  • ¥50 求代做一个阿里云百炼的小实验
  • ¥15 查询优化:A表100000行,B表2000 行,内存页大小只有20页,运行时3页,设计两个表等值连接的最简单的算法
  • ¥15 led数码显示控制(标签-流程图)
  • ¥20 为什么在复位后出现错误帧