Reputation: 4619
function uploadFile() {
global $attachments;
while(list($key,$value) = each($_FILES[images][name]))
{
if(!empty($value))
{
$filename = $value;
//the Array will be used later to attach the files and then remove them from server ! array_push($attachments, $filename);
$dir = "/home/blah/Music/$filename";
chmod("/home/blah/Music",0777);
$success = copy($_FILES[images][tmp_name][$key], $dir);
}
//
}
//
if ($success) {
echo " Files Uploaded Successfully<BR>";
//
}else {
exit("Sorry the server was unable to upload the files...");
}
//
}
Trying to upload a file and then send it as an attachment along mail using PHP Mailer
Errors :
Warning: copy(/home/blah/Music/Aerial_view_of_Yamuna_Expressway.jpeg): failed to open stream: Permission denied in /opt/lampp/htdocs/UI/user/joinmeeting.php on line 292
Updated :
blah@my001server:~$ ls -la for /home/blah/Music
ls: cannot access for: No such file or directory
/home/blah/Music:
total 8
drwxr-xr-x 2 blah blah 4096 Jul 4 10:20 .
drwxr-xr-x 67 blah blah 4096 Sep 21 10:18 ..
Why my linux system is not permitting to copy the file ?
Upvotes: 0
Views: 412
Reputation: 43884
Ok your edit is a bit weird.
blah@my001server:~$ ls -la for /home/blah/Music
ls: cannot access for: No such file or directory
/home/blah/Music:
total 8
drwxr-xr-x 2 blah blah 4096 Jul 4 10:20 .
drwxr-xr-x 67 blah blah 4096 Sep 21 10:18 ..
That command is erroranous since it is actually:
blah@my001server:~$ ls -la /home/blah/Music
You should be running.
But ok I see a problem. The file .
which denotes the entire folder has no www-data
permissions. This means that the default webuser for your Linux distro probably does not have access those files.
Since PHP runs under webuser www-data
Linux will not permit it to cp
or vi
or gedit
(or anything else for that matter) it anything it is not owning.
You can try:
sudo chown /home/blah/Music www-data
Instead. This should give some permission to www-data
to take control of files within the directory.
Of course this raises even bigger problems. Ideally you would want to disconnect any upload dir or anything from your actual web server due to security needs.
Upvotes: 0
Reputation: 618
Check permissions for target folder.
Set 777 and try again
$ chmod 777 folder
So as we see now you dont set write permission to Music folder.
Set it manualy from console, not from php script.
Upvotes: 1
Reputation: 241
Try with move_uploaded_file (http://php.net/manual/en/function.move-uploaded-file.php) instead of copy :
move_uploaded_file($_FILES[images][tmp_name][$key], $dir);
Upvotes: 0