Jump to content

image upload not returning empty


davey_b_

Recommended Posts

i have a basic upload image script but when no image is selected it still puts "productsmall_1209413585" in the database.

 

if the image is true then "productsmall_1209412913ne_grp1.gif" is entered and all works fine...

 

what have i done wrong??

<?php   //////////// Image config //////////////

$picsmall = $_FILES['userfile'][0];
    $picbig = $_FILES['userfile'][1];

    $picsmallname = $_FILES['userfile']['name'][0];
    $picbigname = $_FILES['userfile']['name'][1];

    $picsmalltype = $_FILES['userfile']['type'][0];
    $picbigtype = $_FILES['userfile']['type'][1];

$final_image_big = "productlarge_".time().$picbigname;
$final_image_small = "productsmall_".time().$picsmallname;

$picsmalldest = $prodimagedir . $picsmallname;
$picbigdest = $prodimagedir . $picbigname;

if (!is_readable($prodimagedir) || !is_writable($prodimagedir) || !is_executable($prodimagedir)) {
        $error = true;
        $message .= " * Change the permission of 'products' folder in the root to 777 <br>";
    }
if ($picsmalltype != "") {
        if (!isValidWebImageType($picsmalltype)) {
            $message .= " * Invalid product picture (small)! Upload an image (jpg/gif/png)" . "<br>";
            $error = true;
        } else {
            if (file_exists($picsmalldest)) {
                $message .= " * Product picture (small) with the same name exists! Please rename the product picture (small) and upload! " . "<br>";
                $error = true;
            }
        }
    }
if ($picbigtype != "") {
        if (!isValidWebImageType($picbigtype)) {
            $message .= " * Invalid product picture (big)! Upload an image (jpg/gif/png)" . "<br>";
            $error = true;
        } else {
            if (file_exists($picbigdest)) {
                $message .= " * Product picture (big) with the same name exists! Please rename the product picture (big) and upload! " . "<br>";
                $error = true;
            }
        }
    }

 

PS. I need to time stamp it in case 2 images with the same name get uploaded.

Link to comment
https://forums.phpfreaks.com/topic/103316-image-upload-not-returning-empty/
Share on other sites

of course...

here's the rest plus the sql update

<?php 
    if ($message != "") { // error
        $message = "<br>Please correct the following errors to continue!<br>" . $message;
    } else { // no error so insert user details
	if($picsmallname != ""){
		move_uploaded_file($_FILES['userfile']['tmp_name'][0], "../products/".$final_image_small);

		if($_FILES['userfile']['tmp_name'][0] != "")
		{

			chmod("../products/$final_image_small", 0777);

			generateThumbNail("../products/".$final_image_small,"../products/".$final_image_small,150,150);
		}	
	}
	if($picbigname != ""){
		move_uploaded_file($_FILES['userfile']['tmp_name'][1], "../products/".$final_image_big);

		if($_FILES['userfile']['tmp_name'][1] != "")
		{
			chmod("../products/$final_image_big", 0777);

			generateThumbNail("../products/".$final_image_big,"../products/".$final_image_big,400,400);
		}	
	}
	$sql = "UPDATE  ".$tableprefix."products SET
		product_name = '".addslashes($txtProductName)."',
		product_code = '".addslashes($txtProductCode)."',
		product_description = '".addslashes($txtDescription)."',
		product_short_desc = '".addslashes($txtShort_desc)."',
		product_price = '".addslashes($txtPrice)."',
		product_postage = '".addslashes($txtPostage)."',
		product_addpostage = '".addslashes($txtAddpostage)."',						
		product_youtube = '".addslashes($txtYoutube)."',
		product_category = '".addslashes($ddlCategory)."',
		product_tags = '".addslashes($txtTags)."',
		";
	if($picsmallname != ""){
		$sql .= "product_image_small = '".addslashes($final_image_small)."',";
	}
	if($picbigname != ""){
		$sql .= "product_image_big = '".addslashes($final_image_big)."',";
	}

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.