更改 PHP 上传文件的权限 [英] Change permissions of file uploaded by PHP
本文介绍了更改 PHP 上传文件的权限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我为我正在处理的网站创建了一个小型 CMS,并且有一个表单可以上传要在网站上使用的图像文件.它成功上传文件,但它设置的权限不允许在浏览器中查看文件.
I have created a small scale CMS for a website I am working on and have a form that uploads image files to be used on the website. It uploads the files successfully but the permissions it sets do not allow the file to be viewed in a browser.
这是我当前上传文件的 PHP 代码
Here is my current PHP code to upload the files
$typepath = $_POST['filetype'];
$target_path = "../../images/uploads/".$typepath."/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "<p>The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded</p>\n<p>To the directory: <span style=\"font-weight:bold;\">".substr($target_path, 6)."</span></p>";
} else{
echo "There was an error uploading the file, please try again!";
}
推荐答案
PHP 手册 chmod
http://php.net/manual/en/function.chmod.php
chmod("/somedir/somefile", 0755);
在上下文中;
$typepath = $_POST['filetype'];
$target_path = "../../images/uploads/".$typepath."/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
chmod($target_path, 0755);
echo "<p>The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded</p>\n<p>To the directory: <span style=\"font-weight:bold;\">".substr($target_path, 6)."</span></p>";
} else{
echo "There was an error uploading the file, please try again!";
}
这篇关于更改 PHP 上传文件的权限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文