开发者

how to dynamically change the max upload file limit in php?

I want to change the max upload file limit dynamically. means by not chang开发者_如何学Pythoning the php.ini file on server.

Whenever user had uploaded more then 2 mb then my upload limit should be change.
I want to do all this through php.

Thanks in advance.


The limits enforces by upload_max_filesize are enforced before the php script is run, so the setting cannot be changed dynamically with ini_set.

For more information on the file upload ini settings and where they can be changed, see: - http://php.net/manual/en/ini.core.php#ini.sect.file-uploads - http://php.net/manual/en/configuration.changes.modes.php

Assuming by "user" you mean a visitor to your site, there are really only two methods you can enforce such a limit without the file reaching its final destination:

1) Before the upload has occurred: On the client side. You could definitely do this using a java-based uploader. Whether you can get the filesize of the selected file using javascript, I don't know.

2) After the file is uploaded to the server, but before you move it to the final destination (before you run move_uploaded_file)


Try this:

ini_set('upload_max_filesize', your_value_here);

Make sure also that you have specified the correct acceptable settings for:

  • file_uploads
  • upload_max_filesize
  • max_input_time
  • memory_limit
  • max_execution_time
  • post_max_size


If you can't modify your php.ini, you might be able to do it with a .htaccess file:

php_value upload_max_filesize 50M
php_value post_max_size 50M
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜