doukenqiong0588 2014-02-27 16:15
浏览 21
已采纳

PHP文件上传无效

So I built this simple script to upload files to an XAMPP server, and . . . it didn't work. When I ran it, it dies after the first if statement. EDIT: FIXED

Here's the FIXED html code:

<!DOCTYPE html>

<html>
<head>
<title>Awesome Life: File Upload</title>
<link rel="stylesheet" href="forms.css">
</head>
<body>
<div id="big_wrap">
    <section id="sign_up">
        <form action="http://localhost/mail.php" method="post" ENCTYPE="multipart/form-data">
            <span id="upText">File to Upload</span> 
            <br />
            <input style="margin-top:5px;" type="file" name="fileName">
            <br />
            <br />
            <input type="submit" id="button" name="submit" value="Upload">
        </form>
    </section>
</div>
</body>
</html>

And here's the FIXED script:

<?php
if(!isset($_FILES["fileName"])){
    die("It didn't work!");
}else{
    move_uploaded_file($_FILES["fileName"]["tmp_name"], "\xampp\htdocs\".$_FILES["fileName"]  ["name"]) or die("Didn't work");
}
?>

The file type isn't determined or tested, as I'm not going to be using this on the World Wide Web. I'm simply wondering why it doesn't work. Thanks!

EDIT: It was a simple matter of changing the edit permissions of the htdocs folder. I unchecked the read-only box and it worked fine. Thanks to all for contributing, and especially to Fred -ii-

  • 写回答

3条回答 默认 最新

  • doumen5491 2014-02-27 16:17
    关注

    multipart/file-data is incorrect. It should be multipart/form-data instead.

    Also, you should use move_uploaded_file to move the uploaded file somewhere. Not copy.

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

报告相同问题?

悬赏问题

  • ¥15 c语言怎么用printf(“\b \b”)与getch()实现黑框里写入与删除?
  • ¥20 怎么用dlib库的算法识别小麦病虫害
  • ¥15 华为ensp模拟器中S5700交换机在配置过程中老是反复重启
  • ¥15 java写代码遇到问题,求帮助
  • ¥15 uniapp uview http 如何实现统一的请求异常信息提示?
  • ¥15 有了解d3和topogram.js库的吗?有偿请教
  • ¥100 任意维数的K均值聚类
  • ¥15 stamps做sbas-insar,时序沉降图怎么画
  • ¥15 买了个传感器,根据商家发的代码和步骤使用但是代码报错了不会改,有没有人可以看看
  • ¥15 关于#Java#的问题,如何解决?