douju7503 2015-06-30 09:20 采纳率: 0%
浏览 125
已采纳

用于测试上传PHP文件的Wamp问题

I'm trying to learn how to upload by using Wamp server.. But unsure is it the settings or my code.

Please enlighten me.

Upload.htmlS

<html>
<head>
<title>File Uploading Form</title>
</head>
<body>
<h3>File Upload:</h3>
Select a file to upload: <br />
<form action="http://localhost/testing/php/file_uploader.php" method="post"
                        enctype="multipart/form-data">
<input type="file" name="file" size="50" />
<br />
<input type="submit" value="Upload File" />
</form>
</body>
</html>

The uploader.php

<?php
if( $_FILES['file']['name'] != "" )
{
   copy( $_FILES['file']['name'], "C:\wamp\www\beta\images" ) or 
           die( "Could not copy file!");
}
else
{
    die("No file specified!");
}
?>
<html>
<head>
<title>Uploading Complete</title>
</head>
<body>
<h2>Uploaded File Info:</h2>
<ul>
<li>Sent file: <?php echo $_FILES['file']['name'];  ?>
<li>File size: <?php echo $_FILES['file']['size'];  ?> bytes
<li>File type: <?php echo $_FILES['file']['type'];  ?>
</ul>
</body>
</html>

The error i've received is ,

Warning: copy(bannerbelow.JPG): failed to open stream: No such file or directory in C:\wamp\www\beta\admin\php\file_uploader.php on line 4
  • 写回答

2条回答 默认 最新

  • dongwen7423 2015-06-30 09:41
    关注

    This works for me:

    <?php
        if( $_FILES['file']['name'] != "" ) {
            $uploadfolder = $_SERVER['DOCUMENT_ROOT']."/beta/images";
            $filename = $_FILES['file']['name'];
    
            move_uploaded_file( $_FILES['file']['tmp_name'], "$uploadfolder/$filename" ) or 
                   die( "Could not copy file!");
        }
        else {
            die("No file specified!");
        }
    ?>
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求小游戏炸弹人中关于敌人的C++代码
  • ¥15 拿到这个服务器最高权限有偿
  • ¥50 来个抓app跳转支付宝转链接的
  • ¥15 remotes安装提示没有description文件
  • ¥15 AttributeError: 'NoneType' object has no attribute 'drop_duplicates'报错
  • ¥15 以下代码,运行结果报错
  • ¥15 Vivado仿真数据出错
  • ¥15 银河麒麟不支持vant等前端框架怎么办?
  • ¥15 vue3的子组件在父页面调用不显示不生效问题
  • ¥15 cadence PEX