如何在文件上传 (PHP) 时分配 chmod 值 0777?

发布于 2025-01-08 04:23:14 字数 1192 浏览 0 评论 0原文

我的系统具有一个对话区域,可以写入 .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."; 
 } 


}
?>

我对我的代码的布局和一般语法表示歉意

My system features a conversation area which writes to and draws from a .txt file. I am obviously able to set the permissions through my FTP client but I'm looking to apply the writable functionailty to all files that are uploaded through my system within the PHP. I'll add that security is not an issue.

    <?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."; 
 } 


}
?>

I apologise for the layout and general syntax of my code

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

江南烟雨〆相思醉 2025-01-15 04:23:14

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

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

Just call chmod('thefile.txt', 0777) on the file after it has been uploaded.

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

浅黛梨妆こ 2025-01-15 04:23:14

chmod

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

chmod:

chmod('/path/to/file.txt', 0777);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文