I'm working on file upload via a webpage with a progress bar using Valums file uploader. Almost everything works fine, but I'm not able to change the default tmp directory, where the file is stored during the upload.
Files should be stored in /upload
directory and not in default system /tmp
directory, because /tmp
is mounted in a RAM disk which has its size limited to 4 MB and user will be uploading files around 10 MB.
I've searched lots of webpages, but none of solutions worked.
I've set temp directory in php.ini
:
upload_tmp_dir =/upload
I've set permissions to the /upload
dir, and apache is owner of the file, so the directory is definitely writable by PHP.
I've set the target path in file uploader to /upload
, because I want the files to be stored after the upload also in this directory. The final result is small files are being uploaded successfuly, but files larger than 4 MB fail to upload-the only reason of this behaviour that comes to my mind is that files are stored in /tmp
during upload. To be sure, I've checked it with sys_get_temp_dir()
and the result was /tmp
-so PHP ignores my php.ini directive or there is some other way to set where files are stored during upload.
Oh, and the last information: open_basedir
isn't set, so the PHP access to disk is only limited by file permissions.
This question is related to
php
file-upload
valums-file-uploader
My problem was selinux...
Go sestatus
If Current mode: enforcing
Then chcon -R -t httpd_sys_rw_content_t /var/www/html
create php-file with:
<?php
print shell_exec( 'whoami' );
?>
or
<?php echo exec('whoami'); ?>
try the output in your web-browser. if the output is not your user example: www-data then proceed to next step
open as root:
/etc/apache2/envvars
look for these lines:
export APACHE_RUN_USER=user-name
export APACHE_RUN_GROUP=group-name
example:
export APACHE_RUN_USER=www-data
export APACHE_RUN_GROUP=www-data
where:
username = your username that has access to the folder you are using group = group you've given read+write+execute access
change it to:
export APACHE_RUN_USER="username"
export APACHE_RUN_GROUP="group"
if your user have no access yet:
sudo chmod 775 -R "directory of folder you want to give r/w/x access"
In my case, it was the open_basedir which was defined. I commented it out (default) and my issue was resolved. I can now set the upload directory anywhere.
I was also facing the same issue for 2 days but now finally it is working.
Step 1 : create a php script file with this content.
<?php
echo 'username : ' . `whoami`;
phpinfo();
?>
note down the username. note down open_basedir under core section of phpinfo. also note down upload_tmp_dir under core section of phpinfo.
Here two things are important , see if upload_tmp_dir value is inside one of open_basedir directory. ( php can not upload files outside open_basedir directory ).
Step 2 : Open terminal with root access and go to upload_tmp_dir location. ( In my case "/home/admin/tmp". )
=> cd /home/admin/tmp
But it was not found in my case so I created it and added chown for php user which I get in step 1 ( In my case "admin" ).
=> mkdir /home/admin/tmp
=> chown admin /home/admin/tmp
That is all you have to do to fix the file upload problem.
I struggled with this issue for a long time... My solution was to modify the php.ini file, in the folder that contained the php script. This was important, as modifying the php.ini at the root did not resolve the problem (I have a php.ini in each folder for granular control). The relevant entries in my php.ini looked like this.... (the output_buffering is not likely needed for this issue)
output_buffering = On
upload_max_filesize = 20M
post_max_size = 21M
Source: Stackoverflow.com