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 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作