如何在文件上传时指定chmod值0777(PHP)?

时间:2012-02-23 20:12:49

标签: php chmod writable 777

我的系统具有会话区域,可以写入和从.txt文件中提取。我显然能够通过我的FTP客户端设置权限,但我希望将可写功能应用于通过我的系统在PHP中上传的所有文件。我要补充一点,安全性不是问题。

    <?php

$adminID = $_GET['adminID'];

$name = stripslashes(trim($_POST['name']));
$area = stripslashes(trim($_POST['area']));

mysql_query("INSERT INTO chat_rooms (id, name, area, adminID) VALUES ('', '$name', '$area', '$adminID')");

$image = ($_FILES['image_url']['name']);
$empty = '';


if ($image == $empty)

{
    echo 'NO IMAGE';


}else
{

 $target = "room/test/"; 
 $target = $target .basename($_FILES['image_url']['name']); 
 $target2 = basename($_FILES['image_url']['name']); 



 $image_url = ($_FILES['image_url']['name']);
 $adminarea = 'admin-index.php'; 


mysql_query("UPDATE chat_rooms set file='$image_url' WHERE name = '$name'");



 if(move_uploaded_file($_FILES['image_url']['tmp_name'], $target))
 {

 echo "";
 echo "Your room has been created using the file " . basename( $_FILES['image_url']['name']) ." <br /> <br /> Click <a href=".$adminarea."> here </a> to return to the admin area"; 
 } 
 else { 

 echo "Sorry, there was a problem uploading your file."; 
 } 


}
?>

我为代码的布局和一般语法道歉

2 个答案:

答案 0 :(得分:2)

在文件上传后,只需在文件上调用chmod('thefile.txt', 0777)即可。

http://php.net/manual/en/function.chmod.php

答案 1 :(得分:1)

<强> chmod

chmod('/path/to/file.txt', 0777);