文件的更改权限上传由PHP [英] Change permissions of file uploaded by PHP

查看:268
本文介绍了文件的更改权限上传由PHP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个小规模的CMS一个网站我工作,并有一个表格,上传图像文件到网站上使用。它成功地上传文件,但它设置权限不允许在浏览器中查看该文件。

下面是我当前的PHP code上传的文件

  $ typepath = $ _ POST ['文件类型'];$ target_path =../../images/uploads/\".$typepath.\"/;$ target_path = $ target_path。基本名($ _FILES ['UploadedFile的'] ['名']);如果(move_uploaded_file($ _ FILES ['UploadedFile的'] ['tmp_name的值'],$ target_path)){
    回声&所述; P>将文件。基本名($ _FILES ['UploadedFile的'] ['名'])。
    已上传< / P> \\ n< P>向目录:LT;跨度风格= \\FONT-重量:大胆; \\>中SU​​BSTR($ target_path,6)< / SPAN> &所述; / p>中;
}其他{
    回声发生错误上传文件,请重试!
}


解决方案

PHP Manaual 搭配chmod http://php.net/manual/en/function.chmod.php

 搭配chmod(/ somedir / somefile,0755);

在上下文中;

  $ typepath = $ _ POST ['文件类型'];$ target_path =../../images/uploads/\".$typepath.\"/;$ target_path = $ target_path。基本名($ _FILES ['UploadedFile的'] ['名']);如果(move_uploaded_file($ _ FILES ['UploadedFile的'] ['tmp_name的值'],$ target_path)){
    CHMOD($ target_path,0755);
    回声&所述; P>将文件。基本名($ _FILES ['UploadedFile的'] ['名'])。
    已上传< / P> \\ n< P>向目录:LT;跨度风格= \\FONT-重量:大胆; \\>中SU​​BSTR($ target_path,6)< / SPAN> &所述; / p>中;
}其他{
    回声发生错误上传文件,请重试!
}

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.

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 Manaual chmod http://php.net/manual/en/function.chmod.php

chmod("/somedir/somefile", 0755);

In context;

$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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆