Jump to content

Check to see if a field is empty before continuing the script


son.of.the.morning

Recommended Posts

Now this one is a bit of a shit head. I am using a really comprehensive class i found on on the web for upload / re-size / crop but i want to be able to override it's error handling and i am not good enough to start modifying the code in the class with out fucking it up.

 

Firstly i will show you how i have invoked the class.

					if( isset($_FILES['image'] ) ) {

								//Class includes
								include("../scrips/php/cms/database.insert.class.php");
								include ("../scrips/php/cms/img.upload.resize.crop.class.php.php");


								//----------|Start: upload, resize & save
								$your_image = new _image; 

								//----------| Upload orginal image
								$your_image->uploadTo = 'uploads/';
								$upload = $your_image->upload($_FILES['image']);


								//----------| Resize and upload small thumbnail
								$your_image->newPath = 'thums/';
								$your_image->newWidth = 50;
								$your_image->newHeight = 50;
								$resized = $your_image->resize();



								//----------| Resize and upload medium thumbnail
								$your_image->newPath = 'thums2/';
								$your_image->newWidth = 100;
								$your_image->newHeight = 100;
								$resized = $your_image->resize();
								//----------| Getting the image name to insert into the database futher on in the code
								$name = $resized;
								$img_str = explode("/",$name);
								$final_img_name = $img_str['1'];

								echo "Article has been added!";

								//----------------|end

								//----------------| Start database insert (class manipulation)
								$table = "blog_posts"; 
								$title = "'".$_POST['ArticleTitle']."',"; 
								$img = "'".$final_img_name."',"; 
								$post = "'".$_POST['ArticleBody']."',"; 
								$aurthor_id = "'1',";
								$category_id = "'".$_POST['Category']."',";
								$date_posted = "NOW()";


								$values = array("$title","$img","$post","$aurthor_id","$category_id","$date_posted");
								$fields = array('title,','img,','post,','aurthor_id,','category_id,','date_posted'); 
								$obj= new DatabaseInsert;
								$obj->DatabaseConnectionRequire();
								$obj->ArticleInsert($values,$fields,$table);
								//----------------|end
						}

 

As you can see it's fairly basic. What i want to do is before it runs this script and starts including/invoking the class etc, i want to be able to check to see if there is a value been posted from a FILE FORM OBJECT and if there is to proceed with this script, alternatively i want it to execute another code which will handle it in regards to the concept of my page. A simple javascript alert with be ok providing it reloaded the page to it's default state. If any one can help me here i would appreciate it a lot. Thanks

 

Link to comment
Share on other sites

Yes. The form works fine it's just if i submit it with no file in the FILE form object then it uses a error handler from the class. I don't mind the actual error that the class creates but oddly enough everything else on my page vanishes. That's why i want it to be checked and handed in the view point before the class is included to prevent it generating an error. 

Link to comment
Share on other sites

Okay, now I see your problem. You can do one of two things. You can check the name of the image isn't empty, or you can process the $_FILES error code.

if (!empty($_FILES['image']['name'])) {

 

if (isset($_FILES['image']) && $_FILES['image']['error'] == 0) {

 

You can see all the possible error messages here: http://php.net/manual/en/features.file-upload.errors.php

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.