Forum Moderators: coopster

Message Too Old, No Replies

Image upload

         

adamnichols45

8:36 pm on Feb 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi folks,

just a slight problem with my upload.
If the file size is above 50k i display an error message but when i go back with the browser the page is expired how can i work around this please. code is as follows:-

<?php

if(!is_dir($store_dir) )
{
echo("Specified directory is not valid... Exiting");
@unlink($HTTP_POST_FILES['upfile']['tmp_name']);
exit();
}
if( copy($HTTP_POST_FILES['upfile']['tmp_name'],$store_dir.$test3) )
{
echo("");
}
else
{
echo("You did not select an image or<BR> 1. Image file was not jpeg<br>2. Image file was larger than 50k");
}
@unlink($HTTP_POST_FILES['upfile']['tmp_name']);
?>

adamnichols45

4:18 pm on Feb 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



can no one help with this one then please

HeadBut

4:40 pm on Feb 3, 2005 (gmt 0)

10+ Year Member



Are you using :
<input type="hidden" name="MAX_FILE_SIZE" value="50000" />

?

Just a guess (Since no one else is commenting).
Getting the file size right from the browser could help with oversized upload attempts.

Good luck - hope it helps

adamnichols45

5:34 pm on Feb 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



i certainly am using that yes

HeadBut

5:50 pm on Feb 3, 2005 (gmt 0)

10+ Year Member



How to Avoid "Page Has Expired" Warnings:

[shiflett.org...]

This might help.

adamnichols45

7:11 pm on Feb 3, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



that never helped me at all thanks for the post though but i still recieved my errors!

I think i just need a php script that works like this

page 1 -
user selects file to upload

once file is selected check for filesize and if above 50k echo "Please select another image as it is to large" then once image is below 50k the error wont show and the form will submit.

does any body know if this can be done and is there a script out there?

adamnichols45

2:40 pm on Feb 4, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



still no one out there that can help with this please its driving me nuts

HeadBut

3:02 pm on Feb 4, 2005 (gmt 0)

10+ Year Member



Maybe posting this question to a javascript board would be best?

[webmasterworld.com...]

adamnichols45

1:24 pm on Feb 5, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



not really seeing as this is not possible todo in javascript so i understand

HeadBut

5:05 pm on Feb 5, 2005 (gmt 0)

10+ Year Member



If javascript won't do it then you are going to be limited to trapping for the upload_max_filesize in your php file.

Here is some stuff I use:

if(isset($_FILES['userfile']['error'])){

if($_FILES['userfile']['error'] == "1"){
$ErrorUpdateOK = false;
$ErrorMSG = 'The image you have attempted to upload is too large. (Max 2 Meg.)'.$_FILES['userfile']['error'];
}
if($_FILES['userfile']['error'] == "2"){
$ErrorUpdateOK = false;
$ErrorMSG = 'The image you have attempted to upload is too large. (Max 2 Meg.)'.$_FILES['userfile']['error'];
}
if($_FILES['userfile']['error'] == "3"){
$ErrorUpdateOK = false;
$ErrorMSG = 'The uploaded file was only partially uploaded.';
}
if($_FILES['userfile']['error'] == "4"){
$ErrorUpdateOK = false;
$ErrorMSG = 'No file was uploaded.';
}
}
}

hope that helps!

adamnichols45

11:03 am on Feb 6, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Looking at the script it looks as though this is executed on the next page from the upload script is this correct?

jatar_k

7:52 pm on Feb 6, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



yes, that's correct. As long as you mean the script that is targetted by the form action in your upload form.