Ubuntu Server won't upload files with PHP 'move_uploaded_file' - php

I'm trying to upload files using my Ubuntu Virtual Server.
The PHP function moving the uploaded files returns the following error:
"Warning: move_uploaded_file(files/Site Logo.png): failed to open stream: Permission denied in /var/www/test.php on line 5 Warning: move_uploaded_file(): Unable to move '/tmp/phpZB7Mxi' to 'files/Site Logo.png' in /var/www/test.php on line 5"
The directory has permissions 0777 which I set through the SSH and it still doesn't upload. PHP.ini is configured to upload ON and stuff but no luck. I'd guess its permissions problems but I have set it to pretty much RWX for every user?
My code originally was too complex for a video system so I tried a basic code like below:
$file = $_FILES['video']['name'];
echo $file;
move_uploaded_file($_FILES['video']['tmp_name'],"files/".$file);
echo "Done";
This wouldn't work either. So I am guessing it's how the server is configured?

I was getting the same problem, it was permission problem. Just
sudo chmod 777 /var/www/work_pathname/the_upload_pathname/*

A few things to check:
You did check the permissions on files/ using ls -l?
Did you run
chmod 777 /var/www without the -R flag?
Still sounds like a permissions error, something small you might have missed...

Related

php won't upload images?

I have a php script with no erros (I tested it in other servers), the problem is, in this server I cannot upload images from php.
I add 755 to folder, php.ini file upload is on, max file size is 12mb.
I run this:
chown apache /var/www/html/img-img/
chmod 755 /var/www/html/img-img/
but also didn't solve my problem.
my php also try to create a folder to upload images inside img-img (no success):
$pasta = date("dmy");
$pasta_dir2 = "img-img/$pasta";
if(!file_exists($pasta_dir2)){
mkdir($pasta_dir2, 0755);
}
I have this warnings:
move_uploaded_file(img-img/14719222_886454304825512_8860750091242176512_n.jpg): failed to open stream: Permission denied in /var/www/html/teste.php on line 38, referer: http://example.com/teste2.php
PHP Warning: move_uploaded_file(): Unable to move '/tmp/phptZYSam' to 'img-img/14719222_886454304825512_8860750091242176512_n.jpg' in /var/www/html/teste.php on line 38, referer: http://example.com/teste2.php
any ideas how to solve this without break server security?
this solve my problem:
I don't know what it does, but works... if anyone knows, please, answer this and let me know.
sudo chcon -t httpd_sys_rw_content_t /var/www/html/img-img -R
Check if img-img folder exist and try to set 744 permission to all the folders and subfolders of html using chmod -R 0755 /var/www/html/

Xampp / OS X - Unable to create temporary file. Check permissions in temporary files directory

I know that i am not the first one facing this problem, but all the answers didn't help me.
I am running OS X Siera 10.12.6 with Xampp 7.1.9-0 and trying to get a file list from a remote ftp server like this:
$this->log('Changing to destination folder '.$config->folder.' on ftp server.',2);
ftp_chdir($ftpConnection, $config->folder);
This is the returned error message:
Warning: ftp_nlist(): Unable to create temporary file. Check permissions in temporary files directory. in /Users/foobar/Websites/local/foobar/class.importCsv.php on line 158
Warning: Invalid argument supplied for foreach() in /Users/foobar/Websites/local/foobar/class.importCsv.php on line 160
When checking the output of phpinfo(); and looking for any given tmp-setting I get those paths / parameters that might be of interest:
upload_tmp_dir: /Applications/XAMPP/xamppfiles/temp/
soap.wsdl_cache_dir /tmp
TMPDIR: /var/folders/qq/912038129312390812903812093/T/
SSH_AUTH_SOCK: /private/tmp/com.apple.launchd.f0uSENezH9/Listeners
upload_tmp_dir: /Applications/XAMPP/xamppfiles/temp/
Apple_PubSub_Socket_Render: /private/tmp/com.apple.launchd.aOzrWGVthG/Render
So I am going to change the folder permissions of all those folders:
chmod a+w /Applications/XAMPP/xamppfiles/temp
chmod a+w /private/tmp/
chmod a+w /tmp
the last one is not working, it returns a "operation not permitted" (yes, I used sudo -i):
chmod a+w /var/folders/qq/9qwrj72x6sz73v2tgf7qddnh0000gn/T/
FYI: I just switched from the builtin Apache-PHP-System in OSX to Xampp so it definitely is some mis-configuration with Xampp.

How do I change chmod settings to allow for file upload?

I've been trying to get get my PHP script to upload files. However, I come across this error:
Warning: move_uploaded_file(images/faceBackground.png) [function.move-uploaded-file]: failed to open stream: Permission denied in /f5/mvcsf/public/portfolios/members_profile_chg.php on line 31
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/f5/mvcsf/tmp/phpjY9EBB' to 'images/faceBackground.png' in /f5/mvcsf/public/portfolios/members_profile_chg.php on line 31
After scouring multiple solutions on Stackoverflow, I got the hint that I should change the chmod settings. So I went into Filezilla and tried to change the file permissions for members_profile_chg.php(which contains the upload script) to 0755 and then to 0644, but neither worked. Any ideas? I'm using nearlyfreespeech as my web server if that makes any difference.
chmod 0777 the images folder instead of files.
Make sure your images directory is accessible and writeable (rwx) for the server user (probably apache).
~$ chmod g+rwx,o+rwx images/
Note that this makes the directory world-writable. Better is to only give the server user access (assuming it is apache):
~$ chown apache images/
~$ chmod g+rwx,o+rx images/
More information can be found here.
The numerical values you want to try are 0775 or 0777.
give permission to target folder folder in which permission 0755 or 0777 will work .also make sure that there is a folder named 'images' in the 'portfolios'
if the images is on the root try
move_uploaded_file("/images/faceBackground.png")

Permission denied when opening or creating files with PHP

I can't create files with php, because the file dosent got permission for that.
I get this error:
Warning: fopen(test.txt): failed to open stream: Permission denied in /web/com/example.com/index.php on line 20
Warning: fwrite() expects parameter 1 to be resource, boolean given in /web/com/example.com/index.php on line 21
Warning: fclose() expects parameter 1 to be resource, boolean given in /web/com/example.com/index.php on line 22
This is the code I was using:
<?php
$file = fopen("test.txt","w");
echo fwrite($file,"Hello World. Testing!");
fclose($file);
?>
Simple as that! This is example code from w3schools.
So I need help to find out how to give the file the needed permissions.
I'm uploading files to my site with the net2ftp FTP web application, if it matters.
The folder your PHP script is trying to write to will probably be owned by the root user. Your PHP script is more than likely running under the www-data user if you're using a default Ubuntu/Apache/PHP setup.
As such you need to:
chown -R www-data:www-data folder
chmod -R g+w folder
If you find PHP is running under a user that is different from www-data then just change the user a group in the first line of code.
PS. change "folder" for your actual folder name.
The user running PHP (usually the apache user) doesn't have write permission on the folder the script is running in. Try using an absolute path, like "/tmp/test.txt" -- tmp is usually writable by any user, but the contents tend to be wiped out on reboot.
I am using Ubuntu and i solved it by running the command below in one directory up from the folder(.i.e uploads) i was writing the files in.
sudo chmod 777 ./uploads

Why is my folder not being visible to the web? or upload-able?

For some odd reason I can no longer access my images in my image folder or any of its contents https://ksc105.kscserver.com/images/list.png or https://ksc105.kscserver.com/images/bold.png. I orginally could not upload files to images and attempted to use chmod a=rw /var/www/images but that did not help. I also upgrade php5 to the latest ubuntu build. What can I do to fix this issue, and what can I do to fix my upload issue?
The current images do not display becuase I get a 403 error:
Forbidden
You don't have permission to access /images/bold.png on this server.
Apache Server at [..].com Port 443
Upload gives me:
warning: move_uploaded_file(/[..].png): failed to open stream: Permission denied in [..]/images.php on line 37
Warning: move_uploaded_file(): Unable to move '/var/tmp/[...].png' to '/var/www/images/nzoom.png' in [..]/images.php on line 37
The [..] is just me taking out useless variables.
PHP 5 on Apache 2 on Ubuntu 9.
I suspect you've messed up the permissions on the directory. You probably want to do:
# chmod 757 /var/www/images
# chmod 644 /var/www/images/*.*
to allow the nobody/apache webserver user to access them
This is a permissions related probably most certainly. I suggest you chmod your:
files to 0644 (or 0666 if Apache is not running as the same [FTP] user)
directories to 0755 (or 0777 if Apache is not running as the same [FTP] user)
This way they will always be executable and you have further write permissions from within your scripts.

Categories