PHP : add write permission to file after move_uploaded_file()

喜夏-厌秋 提交于 2019-12-05 13:33:54

Looks like you need to swap your last two lines, eg

$random_filename = 'uploads/' .  $random_filename . $ext;
chmod(ABS_PATH . $random_filename, 0666);

Be very careful when using relative paths such as 'uploads/' . $random_filename . $ext. If the working file is included into another file, the current directory may differ.

I would recommend something like this

$destFile = __DIR__ . '/uploads/' . $random_filename . $ext;
move_uploaded_file($_FILES['file_poster']['tmp_name'], $destFile);
chmod($destFile, 0666);

where the magic __DIR__ constant always contains the absolute path to the parent directory of the file you're actually in.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!