Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => General

allowing null file field in this script

Ask about general coding issues or problems here.

Moderators: macek, egami, gesf

allowing null file field in this script

Postby pugs421 » Mon Jul 07, 2003 9:11 am

I have a script that allows a file upload and resize of an image.
By default the script was only one file field, and if a user didn't enter a file error messages are recieved. I have customized the script into a much bigger form and I want the user to be allowed not to upload a picture, while still submitting the other fields. I'm posting the portion of the script that displays the error messages and doesnt allow the field to be empty.Error section is after the second row of #####. I'm am leaving off all the functions because I dont think they are needed to solve the problem. I'm new at this stuff so the answer is probably fairly obvious and I'm just missing something.(what else is new)
Code: Select all
<?PHP
#############################################################################################
$IMG_ORG_HEIGHT   = "*";   #Width of original image stored on server
$IMG_ORG_WIDTH  = "250";   #Height of original image stored on server
                  #set to "*" to prevent resizing on the dimension
                  #you will not lost X to Y ratio
                  
$IMG_HEIGHT = 108;      # Accepted height of resized image
$IMG_WIDTH  = 108;      # Accepted width of resized image
                  # read about "*" above

$IMG_ROOT = "./images";      # Relative path to folder where uploaded images will be stored; no ending slash!
         # Like this: $IMG_ROOT = "./img";   
         # Remeber to set proper attributes to that folder. 777 will work :)
$use_imagecreatetruecolor = false; // these flags enble ImageCreateTrueColor(); ImageCopyResampled();
$use_imagecopyresampled     = false;// I cant test them coz my host doesn't allow these...
$JPG_QUALITY   =   90; // output jpeg quality

#############################################################################################
//error_reporting(53); // dont need ur warnings!
if(!$HTTP_POST_FILES ["image"]["tmp_name"] || $HTTP_POST_FILES ["image"]["tmp_name"] =="none") die("<br>");

if( ! $f_org = resizer_main("image","",$IMG_ORG_WIDTH,$IMG_ORG_HEIGHT))die("<br><font color=\"red\"><b>No Image received...</b></font><br>");
if( ! $f_res = resizer_main("image","res_",$IMG_WIDTH,$IMG_HEIGHT))die("<br><font color=\"red\"><b>Not resized :( </b></font><br>");


$sz_org =getimagesize( "$IMG_ROOT/$f_org" );
$sz_res =getimagesize( "$IMG_ROOT/$f_res" );
$fs_org= filesize("$IMG_ROOT/$f_org" );
$fs_res= filesize("$IMG_ROOT/$f_res" );


I hope thats enough to see whats going on. I left out a lot because it would be a lot to look through. Thanks
pugs421
New php-forum User
New php-forum User
 
Posts: 31
Joined: Sat Jun 28, 2003 9:09 pm

Postby Redcircle » Mon Jul 07, 2003 9:38 am

if(!$HTTP_POST_FILES ["image"]["tmp_name"] || $HTTP_POST_FILES ["image"]["tmp_name"] =="none") die("<br>");

instead of having the script die you could have it skip the file processing section.
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Postby pugs421 » Mon Jul 07, 2003 10:11 am

Could I get it to skip that section, or would I have to insert the code that inserts the other fields to the database instead of the die? (i'm new at this)
pugs421
New php-forum User
New php-forum User
 
Posts: 31
Joined: Sat Jun 28, 2003 9:09 pm

Postby Redcircle » Mon Jul 07, 2003 10:22 am

you have to skip the file processing because php will error out on
$sz_org =getimagesize( "$IMG_ROOT/$f_org" );
$sz_res =getimagesize( "$IMG_ROOT/$f_res" );
$fs_org= filesize("$IMG_ROOT/$f_org" );
$fs_res= filesize("$IMG_ROOT/$f_res" );

if the files don't exist.
User avatar
Redcircle
Moderator
Moderator
 
Posts: 830
Joined: Tue Jan 21, 2003 10:42 pm
Location: Michigan USA

Postby pugs421 » Mon Jul 07, 2003 10:29 am

Could you give me an idea of the structure of what you mean by skip it. I'm not asking you to code it, but just push me in the right direction. Thanks
pugs421
New php-forum User
New php-forum User
 
Posts: 31
Joined: Sat Jun 28, 2003 9:09 pm

Postby pugs421 » Mon Jul 07, 2003 7:51 pm

I went back to the books and I still dont know what you mean by skip. Is this done with a conditional statement?
pugs421
New php-forum User
New php-forum User
 
Posts: 31
Joined: Sat Jun 28, 2003 9:09 pm

Postby tranquillo » Tue Jul 08, 2003 3:12 am

a pice of pseudocode for you :)

if (file exist)
{
file processing;
continue;
}
else
{
continue;
}
tranquillo
New php-forum User
New php-forum User
 
Posts: 74
Joined: Sun Nov 24, 2002 6:48 pm
Location: katrineholm


Return to PHP coding => General

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 4 guests

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.