graham23s Posted March 30, 2008 Share Posted March 30, 2008 Hi Guys, i am starting to use more and more functions now but was curious on a few things, this function i wrote quickly: function is_valid_image_type($image_file_type) { if($image_file_type != "image/pjpeg") { return false; } else { return true; } } part of the code that i have implemented it in: if(isset($_POST['submit'])) { // misc vars - max file size 1mb // $max_size = 1048576; // POST vars for the image // $image_file_name = $_FILES['image']['name']; $image_file_size = $_FILES['image']['size']; $image_file_temp = $_FILES['image']['tmp_name']; $image_file_type = $_FILES['image']['type']; // POST for the usual data // $product_name = mysql_real_escape_string(ucwords(strtolower($_POST['product_name']))); $product_desc = $_POST['product_desc']; $product_caid = $_POST['product_cat_id']; $product_pice = $_POST['product_price']; // empty fields // if($image_file_size <= 0) { standard_message("Error","You never uploaded a product image!"); } if(empty($product_name)) { standard_message("Error","You never entered the products name!"); } if(empty($product_desc)) { standard_message("Error","You never entered a description about the product!"); } // file type // //if($image_file_type != 'image/pjpeg') //{ // standard_message("Error","Your uploaded image file doesn't seem to be a .jpg"); //} // file size // if($image_file_size > $max_size) { standard_message("Error","Your uploaded image file is bigger than 1mb"); } // get the files extension // //$extension = substr(strrchr($image_file_name, '.'),0); // lower case the extension // //$extension = strtolower($extension); // check the file type // $test = is_valid_image_type($image_file_type); print $test; so in the function when i return false, i assume that returns 0 and true a 1?, also once the function returns either a 0 or a 1, is it up to me to do something with the digit to stop the script? thanks for any help guys Graham Quote Link to comment Share on other sites More sharing options...
trq Posted March 30, 2008 Share Posted March 30, 2008 so in the function when i return false, i assume that returns 0 and true a 1?, also once the function returns either a 0 or a 1, is it up to me to do something with the digit to stop the script? Most functions (built in or custom) return true or false. So you would call your function like any other.... <?php if (is_valid_image_type($image_file_type)) { echo "Image is valid"; } else { echo "Image not valid"; } ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.