Microsoft
Software
Hardware
Network
Question : adding read permission's to a file using php script
Hello,
I'm using the below two php scripts to upload a file from the client to the server. The file gets to the correct folder but the file needs additional permissions. I need to add "Group" and "Others" read permissions. The uploaded file already has read and write permissions for the owner and I would like for those to stay. Below are the two php functions I'm using to upload the file, can someone help me figure out how to set the read Group and Others permissions for this file. I'm brand new to php.
<?php
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_n
ame'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'] . '/';
$targetFile = str_replace('//','/',$targ
etPath) . $_FILES['Filedata']['name'
];
move_uploaded_file($tempFi
le,$target
File);
}
echo '1';
?>
<?php
// JQuery File Upload Plugin v1.4.1 by RonnieSan - (C)2009 Ronnie Garcia
if (!empty($_FILES)) {
$tempFile = $_FILES['Filedata']['tmp_n
ame'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $_GET['folder'] . '/';
$targetFile = str_replace('//','/',$targ
etPath) . $_FILES['Filedata']['name'
];
// Uncomment the following line if you want to make the directory if it doesn't exist
// mkdir(str_replace('//','/'
,$targetPa
th), 0755, true);
move_uploaded_file($tempFi
le,$target
File);
}
switch ($_FILES['Filedata']['erro
r'])
{ case 0:
$msg = "No Error";
break;
case 1:
$msg = "The file is bigger than this PHP installation allows";
break;
case 2:
$msg = "The file is bigger than this form allows";
break;
case 3:
$msg = "Only part of the file was uploaded";
break;
case 4:
$msg = "No file was uploaded";
break;
case 6:
$msg = "Missing a temporary folder";
break;
case 7:
$msg = "Failed to write file to disk";
break;
case 8:
$msg = "File upload stopped by extension";
break;
default:
$msg = "unknown error ".$_FILES['Filedata']['err
or'];
break;
}
$setupFile = "uploadVARresults.txt";
$fh = fopen($setupFile, 'w');
if ($fh) {
$stringData = "path: ".$_GET['folder']."\n targetFile: ".$targetFile."\n Error: ".$_FILES['Filedata']['err
or']."\nEr
ror Info: ".$msg;
}
fwrite($fh, $stringData);
fclose($fh);
echo '1';
?>
Answer : adding read permission's to a file using php script
move_uploaded_file($tempFi
le,$target
File);
chmod(744); // 7 read write and execute for owner , 4 is read only for group and others
Hope this helps
Random Solutions
windows installer problem
Show All Records In Query if Nothing Selected in Listbox
Power Point files won't open from samba share
How could i distribute internet to users connected to windows server 2008 R2 ????
ZyXel GS-1548 switch
DNS over a VPN-Tunnel
Unattended Windows 7 Installation answer file not working
How do I add a Folder to Windows Installer without having to add each individual file
How can I determine from an Office 2010 Volume License key (or product activation key) exactly which version of Office 2010 to download & install from MSDN (msdn.microsoft.com)?
PHP.ini file 'display_errors' is set to Off but errors still appear on page?