欢迎各位兄弟 发布技术文章
这里的技术是共享的
FileField and ImageField 3.0 have just been released and bring with them the ability to display an upload progress meter in the FileField widget while a file is being uploaded. As ImageField uses the FileField widget this works for ImageFields too.
The original article FileField and ImageField 3.0 for Drupal 6 Released points out:
Probably the most exciting improvement is the addition of upload progress indication. This enhancement requires the PECL uploadprogress PHP extension, but adds a real asset to sites that use FileField for podcasts, videos, or other large files.
It took me a while to figure out how to install this extension so I thought I'd do a quick post about it. These instructions are probably valid for other PECL extensions but since this is the only one I have installed I wouldn't like to say for sure.
pecl install uploadprogress
Download the PECL uploadprogress extension
Extract the uploadprogress-1.x.x.tgz archive, cd into the extracted folder and run these commands in Terminal:
Check that the directory for the extensions is correct. The last line of the output returned from the make install
command (on my system) is:
Open php.ini and edit the extension_dir
directive, replacing it with this path.
extension=uploadprogress.so
You should now have the PECL uploadprogress extension installed.
It's very simple to install on Windows:
extension_dir
in php.ini.The pecl4win site was down for maintenance at time of writing so you could try here in the meantime (thanks to chriscohen for the link).
If you're using using WampServer 2 then it already comes with php_uploadprogress.dll installed (thanks again to chriscohen for pointing this out and testing that both methods work).
To increase the maximum filesize you need to set 2 directives:
Generally you should set post_max_size
to double what you set upload_max_filesize
to. This means you can upload 2 files of your maximum limit for each POST and seems like a good middle ground.
The memory_limit
directive should also be set above the value of post_max_size
so your server can handle the uploads.
There are 2 ways you can set this directive:
Edit php.ini and modify these directives:
Edit .htaccess and add:
Adjust 128M and 256M with the sizes you require.
You could edit the memory_limit
directive in php.ini but I personally like to set that directive on a site-by-site basis. This helps to keep sites that don't need such a large memory_limit
nice and efficient.
Instead you can set the directive in settings.php by adding this line just below the other ini_set
lines:
@Kyle Mathews: Thanks for pointing that out, I forget to write about it in the original post. When I tried to run it I got this error:
This is why I had to go the manual route. If pecl install uploadprogress
works then that's obviously much easier!
Or just type "pecl install uploadprogress" which accomplishes the same thing on at least Linux. You'll still need to add the line to php.ini.
Hadn't realized though you needed to install uploadprogress to get the bar. It looks nice.