Forum Moderators: coopster

Message Too Old, No Replies

Detect uploads and respond accordingly

Some users recieve a thank you page,others are sent an email confirmail

         

moroose

3:43 am on May 31, 2007 (gmt 0)

10+ Year Member



ok,I spend 2 days fetching the php forum pages about something i want to achieve but to no exact result.
If some can share their thoughts on this,i'd be very grateful.
Bottom line:
Is there a way to detect that an upload has taken place and act accordingly before data is inserted in the database?
Like i have a form where users that only submit regular input recieve a thank you page,but those who attach an upload will be sent an email confirmtion instead.Even nicer,the script checks their email against a db and if true,they are not required to confirm their email and are treated as normal(recieve a thank you page immediately)
Thanks in advance

Habtom

5:38 am on May 31, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



For the file you mentioned, you are going to have an upload PHP script (I think you already have it).

if(move_uploaded_file($_FILES['fileupload']['tmp_name'], $target)) {
echo "". basename( $_FILES['fileupload']['name']).
" uploaded";
} else{
echo "Error Occurred!";
}

If $_REQUEST['fileupload'] is not empty and the file is uploaded, then you can send the email you considered sending, if it is empty you know for sure from the very begining, the person is not intending to send attachments.

Habtom

moroose

7:17 am on May 31, 2007 (gmt 0)

10+ Year Member



Yes,i already have the upload script in place.
From my understanding of basic concepts i can tell upload detection is achievable via $_FILE as well.Am not just proficient at php coding.
Hope someone can get me started with some if/else file upload detection code,using either way.something along the lines of :
if no file uploaded,echo thank you page,
else require an email confirmation
My gratitude in advance!

barns101

8:38 am on May 31, 2007 (gmt 0)

10+ Year Member



Similar to what Habtom posted:

if(move_uploaded_file($_FILES['fileupload']['tmp_name'], $target))
{

// Send confirmation email
mail('user@example.com', 'Subject', 'Message');

// Redirect to thank you page
header('Location: http://www.example.com/thankyou.php');

}
else
{
echo 'Error Occurred!';
}

moroose

8:51 am on May 31, 2007 (gmt 0)

10+ Year Member



THAT what i was looking for .
Thank you Habtom and Barns!
While am still here for few minutes,can any one of you give me an opinion as to what is the reasonble(standard)upload_max_filesize for posting a dissertation(almost a medium sized magazine).We're on shared hosting,so i assume the default limit is 2M,but can it be overwridden?

Habtom

9:03 am on May 31, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To change the maximum upload file size, do the following:

Set the values where it is important, probably in one of your global.php files (or something similar):
ini_set('upload_max_filesize', '8M');

Or even better in .htaccess file:
php_value post_max_size 8M
php_value upload_max_filesize 8M

If you can get the chance to edit the php.ini, you have the option there as well

Habtom

moroose

9:19 am on May 31, 2007 (gmt 0)

10+ Year Member



My host runs php 4,so i assume i'll have it as you suggest:
<IfModule mod_php4.c>
php_value upload_max_filesize 8M
php_value post_max_size 10M
</IfModule>

Just tried the upload detection code and it worked a treat.I wish if i can extend it so it checks the uploading user'email against the db,and if a match found,they are directed to just the thank you page (no email confirmation req)