0

这是上传表单的代码,使我能够将图像上传到数据库

<html>
<head>
<title>File Uploading Form</title>
</head>

<body>
<h3>File Upload:</h3>
Select a file to upload: <br />

<form action="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>

这是我在名为 file_uploader.php 的文件中的代码。尝试完成此操作时,我收到错误无法复制文件!

<?php
if( $_FILES['file']['name'] != "" )
{
   copy( $_FILES['file']['name'], "databasehostdetails" ) 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>
4

2 回答 2

0

你需要使用tmp_name. 还有,什么是databasehostdetails?第二个参数是目标(您要将文件复制到的位置)。

copy($_FILES['file']['tmp_name'], DESTINATION_PATH);
于 2013-04-27T19:09:13.043 回答
0
于 2013-04-27T19:20:02.217 回答