 |
| PHP How-To Post your "How do I do this with PHP?" questions here. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the PHP How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

June 9th, 2006, 11:23 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
Get user input during form processing
Here is the exact problem I am working on...
My specs call for the uploading of user files, and I need to check the size and type of file before saving them. I can do the type check and subsequent return to the entry form if it fails. What I need is a way to notify the user if the size exceeds a certain amount, and ask if they still want to upload it. I think I can do it in a very long, round about way with javascript, but it would be much easier if I could just popup a message box to the user and then either upload or return to the original page depending on their answer. Is this even possible with PHP?
Thanks
Mike
Mike
EchoVue.com
__________________
Mike
EchoVue.com
|
|

June 10th, 2006, 02:51 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
|
|
Read my FAQ on uploading files:
http://p2p.wrox.com/topic.asp?TOPIC_ID=12104
That explains hows to look at values for size, mime type, etc.
There are several configuration directives in PHP.ini that control the size of the file that you can upload, if you want to be able to go past a certain file size ceiling and be able to tell the user the file is too large, you might have to tweak the parameters of the following directives.
file_uploads, max_input_time, memory_limit, post_max_size, upload_max_filesize, max_execution_time
http://www.php.net/manual/en/ini.php
Whether or not you have to tweak the values of those directives depends entirely on what you plan to do with the uploaded file, and how big the uploaded file is to be. You'll also want to be especially careful with these in a shared hosting enviornment, botching something up with one of those could lead to the server being brought to its knees or crashing entirely.
HTH!
Regards,
Rich
--
Author,
Beginning CSS: Cascading Style Sheets For Web Design
CSS Instant Results
http://www.catb.org/~esr/faqs/smart-questions.html
|
|

June 10th, 2006, 02:59 PM
|
|
Friend of Wrox
|
|
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
|
|
Hi Richard,
Thanks, that is going to help a lot.
The key thing I am looking for, but fear is not possible, would be to set a specific size on the file, and then if the file is larger than that, prompt the user to cancel or continue with the upload.
Any ideas?
Thanks
Mike
Mike
EchoVue.com
|
|

June 10th, 2006, 11:54 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
|
|
Why would you want to offer the "Continue" option if you know the file is too big? That aside, if you want to offer a prompt when the file is too big, you'd have to use a bit of scripting. Basically what I'd do, is set the form to target a hidden <iframe> (using the target attribute on the <form>). The script there can output from the server whether there were any problems with the file upload, you'd just output to the <iframe> JavaScript containing an event that fires onload to display your prompt. Though, at that point you've already uploaded the file and determined it was too big, so I'd just display an error by the upload field; There's no need for the prompt at that point. I use this method all the time in an AJAX-driven file management tool I designed (since files can't be uploaded through AJAX and still have cross-browser compatibility). Thing is, you can't check the file size on the client-side before upload takes place without having to jump through all sorts of security hurdles. Best thing to do is just upload it, and if it's too big, just bring back an error from the server.
That make sense?
Regards,
Rich
--
Author,
Beginning CSS: Cascading Style Sheets For Web Design
CSS Instant Results
http://www.catb.org/~esr/faqs/smart-questions.html
|
|
 |