在php中移动上载的文件
我正在尝试将上载的文件替换到某个位置 我的代码是:在php中移动上载的文件,php,Php,我正在尝试将上载的文件替换到某个位置 我的代码是: if (isset($_FILES['image']['name'])) { $saveto = 'img/$user.jpg'; //$user would be the name of the current user. move_uploaded_file($_FILES['image']['tmp_name'], $saveto); } 我得到了这个错误 Warning: move_upload
if (isset($_FILES['image']['name']))
{
$saveto = 'img/$user.jpg'; //$user would be the name of the current user.
move_uploaded_file($_FILES['image']['tmp_name'], $saveto);
}
我得到了这个错误
Warning: move_uploaded_file(img/$user.jpg): failed to open stream: Permission denied in /Applications/XAMPP/xamppfiles/htdocs/profile.php on line 33
尽管设置了权限,sudo chmod 777
。它仍然给我这个错误,有什么问题吗?谢谢两件事
首先,将$saveto='img/$user.jpg'
至$saveto=“img/$user.jpg”代码>。在PHP中,使用“
和”
声明字符串具有不同的行为。使用“
它不会将$user
的值提取到字符串中,而是将$user
逐字写入
但这不是错误。错误是您没有在目录/img/
中创建文件的权限。请确保在此文件夹中设置了正确的权限
或者可能是因为$
在Linux中不是文件名的有效符号,但我不确定这一点