douju7503
2015-06-30 09:20 浏览 120
已采纳

用于测试上传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 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!");
        }
    ?>
    
    点赞 评论 复制链接分享
  • duankang5285 duankang5285 2015-06-30 09:38
    $path = 'C:\wamp\www\beta\images\'; // make sure dir is exist 
    
    if(!is_dir($path)){
       mkdir($path)
    }
    
    //write code for move file  via copy or move_uploaded_file funcition
    
    点赞 评论 复制链接分享

相关推荐