douzoudang1511 2013-12-06 11:08
浏览 75
已采纳

尝试让用户将文件上传到我的网站,但有一些错误

Here is my HTML code :

<form enctype="multipart/form-data" action="new1.php" method="POST">
    Choose File: <input name="userfile" type="file" /><br />
    <input type="submit" value="Upload File" />
</form>

And this is my PHP code :

<?php
   $path = "files/";
   $path = $path.basename( $_FILES['userfile']['name']);
   if(move_uploaded_file($_FILES['userfile']['tmp_name'], $path)) {
       echo "Success uploading". basename($_FILES['userfile']['name']);
   } else{
       echo "Error when uploading file.";
   }
?>

Here are the errors I got when running on XAMPP

Warning: move_uploaded_file(files/ChicKissLove.jpg): failed to open stream: No such file or directory in C:\xampp\htdocs\phptest
ew1.php on line 7

Warning: move_uploaded_file(): Unable to move 'C:\xampp\tmp\phpAF97.tmp' to 'files/ChicKissLove.jpg' in C:\xampp\htdocs\phptest
ew1.php on line 7
Error when uploading file.

Anyone can find out what's wrong ? I 'm unable to upload the files.

  • 写回答

3条回答 默认 最新

  • doubi8965 2013-12-06 11:14
    关注

    Create files directory in the same directory where your code is first. And You are good to go.

    P.S next time save your files with a random name because someone else might upload a file with same name creating more problems and always filter your uploading files never allow executable files.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 linux驱动,linux应用,多线程
  • ¥20 我要一个分身加定位两个功能的安卓app
  • ¥15 基于FOC驱动器,如何实现卡丁车下坡无阻力的遛坡的效果
  • ¥15 IAR程序莫名变量多重定义
  • ¥15 (标签-UDP|关键词-client)
  • ¥15 关于库卡officelite无法与虚拟机通讯的问题
  • ¥15 目标检测项目无法读取视频
  • ¥15 GEO datasets中基因芯片数据仅仅提供了normalized signal如何进行差异分析
  • ¥100 求采集电商背景音乐的方法
  • ¥15 数学建模竞赛求指导帮助