我正在尝试使用Wamp服务器学习如何上传.. 但不确定的是设置还是我的代码。
请赐教。
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>
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>
我收到的错误是,
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
答案 0 :(得分:0)
$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
答案 1 :(得分:0)
这对我有用:
<?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!");
}
?>