如何将上传的文件保存在本地主机上?
我一直使用从 HTML5/JS 上传图像文件并使用 PHP 脚本将其保存在 localhost(/var/www/) 中,但我无法保存它。当 _FILES 对象中存在对象时,函数 move_uploaded_file 始终返回 false。我是 php 新手:
$target = "upload/";
if(!empty($_FILES))
{
if(move_uploaded_file($_FILES['image_file']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['image_file']['name']). " has been uploaded...";
}
else {
echo "Sorry, there was a problem uploading your file. {$error}";
}
}
else
{
echo "_files is empty";
}
I have been using to upload an image file from HTML5/JS and using PHP script to save it in localhost(/var/www/) but i cant save it. the function move_uploaded_file always returns false while there is exists an object in _FILES object. I am a newbie in php:
$target = "upload/";
if(!empty($_FILES))
{
if(move_uploaded_file($_FILES['image_file']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['image_file']['name']). " has been uploaded...";
}
else {
echo "Sorry, there was a problem uploading your file. {$error}";
}
}
else
{
echo "_files is empty";
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试一下
因为您需要指定文件名,而不仅仅是目录。
请参阅 PHP 文档 中的示例
Try
Because you need to specify the name of file, not only the directory.
See example from PHP documentation
试试这个
try this