0

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

Ollie Jones
  • 437
  • 1
  • 9
  • 16
  • If your file-system supports it, [`chmod`](http://php.net/chmod) is a good start. If you create files / directories, see [`umask`](http://php.net/umask) as well. How are the files uploaded? – hakre Feb 23 '12 at 20:18

2 Answers2

2

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

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

spencercw
  • 3,320
  • 15
  • 20
  • I'm still having some trouble, I've included my code segment in the original post in hope that someone may be able to determine where I should apply the chmod. – Ollie Jones Feb 23 '12 at 20:28
  • @OllieJones Put it in after `move_uploaded_file` if it returns `true`. You will need to pass `$target` to `chmod()`. – spencercw Feb 23 '12 at 20:47
1

chmod:

chmod('/path/to/file.txt', 0777);
simshaun
  • 21,263
  • 1
  • 57
  • 73