我目前正在关注基本媒体文件上传表单的教程。我尝试将其添加到我的网站,但我总是收到消息“上传文件时出现错误,请重试!”当我尝试使用它上传图片时。如何让我的网站用户上传媒体文件?
我已经把下面的HTML文件到我的服务器:
<DOCTYPE! html>
<html>
<head>
</head>
<body>
<form enctype="multipart/form-data" action="uploader.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
</body>
</html>
我已经那么创建的文件uploader.php,它看起来像这样:
<?php
// Where the file is going to be placed
$target_path = "../uploads/";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename($_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename($_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
我已经存储在这些文件在同一个目录中。然后我创建了另一个名为uploads的目录 - 这是可写的。
为什么这不起作用?
编辑:我现在能够上传大小为1MB的文件,但大于此的任何内容都无法上传。正如你可以在HTML脚本中看到的,我已经将最大文件大小设置为10MB - 所以这应该起作用。任何想法为什么不是?
**上传**文件夹位于写入此代码的同一文件夹中或位于此文件夹之外? –
是的,它在同一个文件夹中。 –
然后,给'$ target_path =“uploads /”;'而不是这个'$ target_path =“../ uploads /”;' –