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.
The problem described here was solved by me quite a long time ago but I don't really remember what was the main reason that uploads weren't working. There were multiple things that needed fixing so the upload could work. I have created checklist that might help others having similar problems and I will edit it to make it as helpful as possible. As I said before on chat, I was working on embedded system, so some points may be skipped on non-embedded systems.
Check upload_tmp_dir in php.ini. This is directory where PHP stores temporary files while uploading.
Check open_basedir in php.ini. If defined it limits PHP read/write rights to specified path and its subdirectories. Ensure that upload_tmp_dir is inside this path.
Check post_max_size in php.ini. If you want to upload 20 Mbyte files, try something a little bigger, like post_max_size = 21M. This defines largest size of POST message which you are probably using during upload.
Check upload_max_filesize in php.ini. This specifies biggest file that can be uploaded.
Check memory_limit in php.ini. That's the maximum amount of memory a script may consume. It's quite obvious that it can't be lower than upload size (to be honest I'm not quite sure about it-PHP is probably buffering while copying temporary files).
Ensure that you're checking the right php.ini file that is one used by PHP on your webserver. The best solution is to execute script with directive described here http://php.net/manual/en/function.php-ini-loaded-file.php (php_ini_loaded_file function)
Check what user php runs as (See here how to do it: How to check what user php is running as? ). I have worked on different distros and servers. Sometimes it is apache, but sometimes it can be root. Anyway, check that this user has rights for reading and writing in the temporary directory and directory that you're uploading into. Check all directories in the path in case you're uploading into subdirectory (for example /dir1/dir2/-check both dir1 and dir2.
On embedded platforms you sometimes need to restrict writing to root filesystem because it is stored on flash card and this helps to extend life of this card. If you are using scripts to enable/disable file writes, ensure that you enable writing before uploading.
I had serious problems with PHP >5.4 upload monitoring based on sessions (as described here http://phpmaster.com/tracking-upload-progress-with-php-and-javascript/ ) on some platforms. Try something simple at first (like here: http://www.dzone.com/snippets/very-simple-php-file-upload ). If it works, you can try more sophisticated mechanisms.
If you make any changes in php.ini remember to restart server so the configuration will be reloaded.
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
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"
My problem was selinux...
Go sestatus.
If Current mode: enforcing then chcon -R -t httpd_sys_rw_content_t /var/www/html
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.
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.
Related
I'm setting up a WordPress site and was prompted to increase my PHP max input vars and the memory limit, but all attempts have reigned no results. I managed to change the memory limit with no issues, however, the input vars still remains the same.
I've created a php.ini file and placed in the root directory, and that didn't work. I created a user.ini file in the same location, didn't work either. I even placed it in the wp-admin file and still no dice. I tried to update the .htaccess file because that was a recommended solution, and still no kosher.
This is the line I've placed within the php.ini file: max_input_vars = 3000
So far I had expected any of the different solutions to have removed that error, but still, nothing has changed and I'm all out of ideas. Any pointers are greatly appreciated, and if more details are needed do let me know and I will add as such.
You may try editing the wp-config file in the document root /var/www/html and add the Directive for wp-config.php. Kindly see it below:
#ini_set( 'max_input_vars' , 4000 );
To gain access to the wp-config file you will need to FTP or SSH to the server.
You may also try editing the php.ini file. In my case, it is located at /etc/php/7.0/apache2/php.ini since I am using apache2 for my wordpress site. You may use the "find / -name *php.ini" command to locate your php.ini file and use vi command to edit the file.
; max_input_vars = 1000
You need to remove the semicolon and change the value that you want to use. Don't forget to restart the Apache service.
$ service apache2 restart
To check if you successfully changed the value, you may create a phpinfo.php file in the document root. Edit the file named phpinfo.php and copy the following code.
<?php
phpinfo();
?>
Hope this information helps you.
I am trying to download this template on Joomla 3.2 extension manger :
http://scriptmafia.org/templates/115622-yt-moustache-yootheme-for-joomla-25-32.html
but every time I upload it, it gives me this error:
There was an error uploading this file to the server.
I have read articles about "increase the upload max size in the php.ini file".
I have tried to find this file in the administrator files section in Joomla, but it is "not found".
So how can I fix this problem? It has not happened for this template only, it has happened for several. So I am almost sure it is due to the upload size.
Edit your php.ini and increase *upload_max_filesize* and *post_max_size*; then restart your web server.
If you don't know where is your php.ini, create a php file to discover: echo php_ini_loaded_file();
The returned path is where your php.ini is located.
EDIT
Well, seems like you have a permission error and not size limit. Try to change permissions of the temp Joomla folder (you can see/configure it on Global Configuration > System).
If you are using XAMPP , php.ini file will be located in c:\XAMPP\php folder. Find the file and increase file upload size there.
If you are using WAMP, You can find ini file in /wamp/bin/php directory.
The location may vary from one OS to another.
You can follow this link:
http://www.cyberciti.biz/faq/linux-unix-apache-increase-php-upload-limit/
You can call in your script ini_set function and change values, which have been stored in php.ini (any changes has affected only for current script, but not for global settings)
ini_set('post_max_size', "%value in MiB for example 16M%")
ini_set('upload_max_filesize', "%value in MiB for example 16M%")
You can read more about it at php.net
If you can't resolve the PHP limitation easily, an alternative is to FTP the installation file to the /tmp folder and in Extension Manager -> Install, use the "Install from Directory" option instead.
Had the same issue for the longest time, none of the answers helped. Found that if you are using GoDaddy, and go to your CPanel, scroll down to Software, then choose PHP version, switch to PHP Options, there you can change your upload file size. Hope this helps, took me forever to find it.
Some people might be having a issue with the memory allocation portion of php.ini file "memory_limit" the default for me was 128mb and i was attempting to upload nearly 300mb and it hit that roadblock. After changing the default value to 512mb and restarting the server i was able to get past this limit.
How to change post_max_size and upload_max_filesize in a local installation of Joomla 3 in XAMPP
You can check the php setting in two places – site’s backend under system information – go to php information. Or on browser go to localhost and click on phpinfo. You’ll find the post and upload part under “Core” heading.
Go to c:\xampp\php\
Find the file php.ini
Open php.ini in notepad
Find post_max_size and change value to 20M
Find upload_max_filesize and change value to 20M
Save the file
Logout out of your site backend.
Turn off apache and mysql on xampp and quit
Restart xampp as administrator
Turn on apache and mysql
Open browser and go to localhost
Open phpinfo and search for upload_max_filesize and post_max_size.
Confirm that changes are registered.
This can also happen with the following suhosin setting:
suhosin.upload.disallow_binary = On
Setting it to off temporarily allows you to upload zip files
If you use CPanel, search for PHP version (in the Software section) and click on it, then click on 'switch to PHP Options', the options will display then look for 'upload_max_filesize' and click on the value to change it. Do the same for 'post_max_size'.
I have a web, and running well on my localhost.
After I Upload on my godaddy hosting, My web got a bug. the conclusions is, I MUST change the memory_limit on the php.ini file, BUT cant find php.ini on FTP manager.
I have tried to:
Find the way for change to the Classing FTP manager.
Create / upload php.ini file from local and not work.
My Questions is : How I can Fix this? I Must change php.ini file.
does anyone have experience like me?
Create php.ini file with your desired setting and upload it in your root folder of server. It will take effect with this new setting.
You can't edit the php.ini file of godaddy server, but you can upload your own copy of your php.ini with your new setting.
This new setting will be available only to you. Other websites will not be affected with this new setting.
Previously I faced the same issue, but after doing this my problem was resolved.
Procedures:
Go to your CPanel
Select PHP version
Click on the link Switch to PHP options
Edit your configuration
don't forget to click save
You can also follow this screencast
https://www.youtube.com/watch?v=tdUlIkZcOe0
As pointed out by #Jason, for most shared hosting environments, having a copy of php.ini file in your public_html directory works to override the system default settings. A great way to do this is by copying the hosting company's copy. Put this in a file, say copyini.php
<?php
system("cp /path/to/php/conf/file/php.ini /home/yourusername/public_html/php.ini");
?>
Get /path/to/php/conf/file/php.ini from the output of phpinfo(); in a file. Then in your ini file, make your amendments
Delete all files created during this process (Apart from php.ini of course :-) )
To check whether your php.ini file takes effect, open a plain text editor and create a file called phpinfo.php. Insert the following line:
<?php phpinfo(); ?>
Save this file to the root of your Web site and then browse to yourdomain.com/phpinfo.php to test the settings.
Septiyo,
You need to create your own php5.ini file and upload it to your root directory. Using GoDaddy (as I do) you do not have control over the web/conf/ folder to make any changes to their version. Be sure if you're using PHP5 to name your file php5.ini or php.ini for PHP4. Upload it to your root folder, then restart your page, then check using phpinfo() to see if the directory of your php file has changed correctly.
For more information, check this link out.
http://www.ostraining.com/blog/coding/phpini-file/
if you don't have a good copy of your php5.ini file in your home directory (a predicament that I recently found myself in), you'll need to follow a little multi-step process to make your changes.
Create a little code snippet to look at the output of the phpinfo() call. This is simple, and there are multiple web-sites that describe this process.
Examine the output of phpinfo() for the row which contains Configuration File (php.ini) Path. Mine was in /usr/local/lib, but your's may be a different path (depends on hosting level purchased).
GoDaddy will NOT simply copy this file into your home directory for you --as silly as that sounds! But, you can write a little php program to copy this php.ini file into your home directory. The guy at
https://www.jabari-holder.com/blog/how-to-get-godaddys-php5-ini-file/
has a drop-box with this code snippet, if you care to use it. Just
take care to modify two things:
a. change the path you read 'from' to match the path you uncovered in Step 2.
b. change the output file-name to something of your choosing. You're going to re-name this file in a later step anyway. Let's call our copied file Foo.ini (but it can be anything).
Rename Foo.ini to .user.ini (for most GoDaddy account types).
Create a new php.ini file with your desired settings and upload it to public_html folder of your Godaddy Hosting Account.
By default, Godaddy doesn't allow to edit it's existing php.ini file. However, you can always upload your own copy of your php.ini file with your own settings.
Below is an example of a simple php.ini file with some custom values:
max_execution_time 600
memory_limit 128M
post_max_size 32M
upload_max_filesize 32M
I had this exact problem with my GoDaddy account.
I am running the Linux hosting with cPanel
follow these steps and you should be fine if you are running the same hosting as me:
first, go to you Manage Your Hosting -> Manage
then you will see a section called Files, click on File Manager
you can select the Document Root for: yourwebsite.com then click GO
this should bring you right away in the public_html folder
in that folder, you can add a file (by clicking the +File in top left corner), call it phpinfo.php
right click that new file, and select edit :
right this in it and save changes:
<?php phpinfo(); ?>
it the same public_html folder, add another file called php.ini
edit this one too, right those lines:
max_execution_time 600
memory_limit 128M
post_max_size 32M
upload_max_filesize 32M
now, go back to your Manage Your Hosting -> Manage, look for PHP Process
click Kill Process, this will allows a refresh with your new settings. you are good to go
side note: you can see your new settings by navigating to yourwebiste.com/phpinfo.php
I found a guide to reload the php5.ini file or load a new one right away. You will need to access your Godaddy hosting panel where you will find the option "system process" do a restart there and it will load the php5.ini or php.ini file right away.
2 external guides to assist you:
http://support.godaddy.com/help/article/5980/managing-system-processes-on-linux-hosting-accounts
http://www.studio-owens.com/blog/GoDaddy-and-Your-php-ini-File.htm
For some hosting accounts, I'm on Ultimate Classic Linux, the file name you need to use is .user.ini.
It's an older question, but if anyone has a problem with setting this, their documentation is outdated. I made a copy of the php.ini file named php5.ini and now it works.
Follow below if you use godaddy shared hosting..
its very simple:
we need to access root folder of the server via ftp, create a "php5.ini" named file under public_html folder... and then add 3 stupid lines... also "php5" because I'm using php5.4 for 1 of my client. you can check your version via control panel and search php version. Adding a new file with php5.ini will not hamper anything on server end, but it will only overwrite whatever we are commanding it to do.
steps are simple:
go to file manager..
click on public_html..
a new window will appear..
Click on "+"sign and create a new file in the name: "php5.ini" ... click ok/save. Now right click on that newly created php5.ini file and click on edit... a new window will appear... copy paste these below lines & click on save and close the window.
memory_limit = 128M
upload_max_filesize = 60M
max_input_vars = 5000
Not php.ini file, but a way around it. Go to GoDaddy's
Files > Backup > Restore a MySQL Database Backup
Choose your file and click Upload. No timeouts. Rename the DB if needed, and assign a user in
Databases > MySQL Databases
I run PHP as FCGI! I'm setting upload_tmp_dir option as value /home/domain.com/tmp. When executed phpinfo() for double-check it's confirmed that the settings above are correct.
Nevertheless, when actual upload in happening, the uploading file is temporarily going to /tmp directory with permissions apache:apache and when the upload is fully finished only then the uploaded file is being moved to the destination directory, which was set in upload_tmp_dir. After file is moved it has proper permissions which are domainowner:domainowner.
What's happening with FCGI as described above is absolutely wrong and different from what mod_php or CGI are doing! mod_php and CGI just start uploading a file directly to the upload_tmp_dir and then just rename the file after upload is finished.
I have few considerable concerns about this as follows:
Imagine, what happens if 20 people, finish uploading a file that is around 2GB, right at the same time? Uploaded files will have to be moved to the home directory from /tmp, creating a lot of useless load on file system! Thus, I thought that moving is much more resourceful rather than just renaming a file in the same directory?! Besides /tmp is mounted as ext3 and home as ext4 and what is even worse that /tmp partition is 16GB of space, which is total disaster from what I have imagined above?
Question:
How to force FCGI to use upload_tmp_dirdirective the same way as CGI or mod_php? I haven't found a documented way to change the temp directory it uses.
Please help!?
This issue was discussed at bugs.php.net. The possible solution is that you need to set read attributes on any parent directory to where your tmp folder is, to make it work. It could be a security risk.
I would recommend creating a tmp in /home/tmp setting chmod 777 to both home and tmp
This thread suggests that it may be due to a security level setting. If 'medium' then FCGI defaults to the system default.
Not sure what setting it is referencing though since it is referring to a desktop installation. I will do some digging.
I've tried going through Network Solutions tech support but didn't get it resolved ("You need to talk to Signature Support, which is $50").
I'm running some sites off of a Net Sol VPS account and need to change the upload_max_filesize setting (which is apparently set to a paltry 2MB by default) for the php server. I've added:
upload_max_filesize = 20M
post_max_size = 20M
max_execution_time = 6000
to the /httpdocs/cgi-bin/php.ini file (per NS's instructions), and then restarted apache, but when I run a phpinfo on that domain, the settings are not applied. It still says "2M" for the upload max.
I also tried adding this to the server root at /cgi-bin/php.ini as well, to no effect.
There is no /cgi-bin/.php/php.coalesced.ini file that I can see.
Any ideas? I'm losing my mind with this.
First thought is to check your phpinfo() output for the value listed in the "Loaded Configuration File" setting and make sure that it matches the file you've been editing.
You can't just litter PHP.ini files around and expect PHP to load them. If it's not been told to look for one in that cgi-bin directory, the file will just get ignored.
Check the phpinfo() output - the first section will tell you exactly what .ini files were located/parsed, and their location. e.g. on my home server:
Configuration File (php.ini) Path /etc/php5/apache2
Loaded Configuration File /etc/php5/apache2/php.ini
Scan this dir for additional .ini files /etc/php5/apache2/conf.d
Additional .ini files parsed /etc/php5/apache2/conf.d/curl.ini, /etc/php5/apache2/conf.d/gmp.ini, /etc/php5/apache2/conf.d/mysql.ini, /etc/php5/apache2/conf.d/mysqli.ini, /etc/php5/apache2/conf.d/pdo.ini, /etc/php5/apache2/conf.d/pdo_mysql.ini
if your cgi-bin .ini file isn't listed, then PHP is NOT looking in that directory.
I know this is old but figured I'd share my experience. I tried adding a php.ini file to the /cgi-bin folder as I read was suggested, that didn't appear to work. My solution was to SSH onto the server and make a change to the real php.ini file and then restarting the server.