Jump to content

If no file selected do not add information to database. (problem getting to work


Recommended Posts

my script for image resizing, image upload, and store information into database works great when a file is selected, however when i just click upload with no image selected it creates image filename and everything and takes up rows in database, i cannot have this because i have a code so if there isn't anything in the row for "photo/thumb" columns, it displays separate images "No image available for this item" However I cannot get it to not run the script if there is no image selected. my code is:

 

	//FILE UPLOADED

//i have put had "if ($_POST) { and script below in between these brackets } //------

$myimage = new ImageSnapshot;
//If loading from an uploaded file:
$myimage->ImageField = $_FILES['photo'];
$myimage->Width = 400;
$myimage->Height = 400;
$myimage->Resize = true; //if false, snapshot takes a portion from the unsized image.
$myimage->ResizeScale = 100;
$myimage->Position = center;
$myimage->Compression = 70;
$filename='itemphotos/'.rand(0,9999999).'.jpg';
//saving to a filename
$myimage->SaveImageAs($filename);

//FILE UPLOADED
$myimage2 = new ImageSnapshot;
//If loading from an uploaded file:
$myimage2->ImageField = $_FILES['photo'];
$myimage2->Width = 100;
$myimage2->Height = 80;
$myimage2->Resize = true; //if false, snapshot takes a portion from the unsized image.
$myimage2->ResizeScale = 80;
$myimage2->Position = center;
$myimage2->Compression = 70;
$filename2='itemphotos/thumbs/'.rand(0,9999999).'.jpg';
//saving to a filename
$myimage2->SaveImageAs($filename2);
if ($_POST['photo']!==""){ //<-------------------------this doesn't seem to be working-----the exact code worked with my previous image handling script however
	$name2 = ucwords(strip_tags($_POST['name']));
	$description2 = ucfirst(strip_tags($_POST['description']));
	$result = mysql_query("SELECT * FROM antiques ORDER By id DESC LIMIT 1");
	$getid = mysql_fetch_assoc($result);
	$id = $getid['id'];
	mysql_query("UPDATE antiques SET photo='$filename', thumb='$filename2' WHERE id='$id'");
	print "<script>";
	print "self.location='index.php?node=antiques'";
	print "</script>"; 
	}

else {
	echo $myimage->Err;
}
//END FILE UPLOADED
} 
}

 

 

Oops forgot $_FILES is a multidimensional array. Use

if(!emtpy($_FILES['photo']['name']) && $_FILES['photo']['error'] === 0) {

 

thanks that worked perfectly for that particular usage, however i have the same code for uploading just an image (photo gallery basically) and that code / if(!emtpy($_FILES['photo']['name'])) {  that doesn't work in either the top, or the bottom where the other one is, it inserts it into the database, which isn't making much sense how it works for one but not the other?

Oops forgot $_FILES is a multidimensional array. Use

if(!emtpy($_FILES['photo']['name']) && $_FILES['photo']['error'] === 0) {

 

thanks that worked perfectly for that particular usage, however i have the same code for uploading just an image (photo gallery basically) and that code / if(!emtpy($_FILES['photo']['name'])) {  that doesn't work in either the top, or the bottom where the other one is, it inserts it into the database, which isn't making much sense how it works for one but not the other?

 

Well it works as far as not allowing uploads, but it does jus tthat, doesn't allow uploads even if you select a file..

Oops forgot $_FILES is a multidimensional array. Use

if(!emtpy($_FILES['photo']['name']) && $_FILES['photo']['error'] === 0) {

 

thanks that worked perfectly for that particular usage, however i have the same code for uploading just an image (photo gallery basically) and that code / if(!emtpy($_FILES['photo']['name'])) {  that doesn't work in either the top, or the bottom where the other one is, it inserts it into the database, which isn't making much sense how it works for one but not the other?

 

Well it works as far as not allowing uploads, but it does jus tthat, doesn't allow uploads even if you select a file..

 

 

if(!emtpy($_FILES['photo']['name']) && $_FILES['photo']['error'] === 0) {

 

I guess it helps to spell empty correctly lol :P.. Now it works fine, Thanks, can't believe i didnt see that sooner :P

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.