Jump to content

Should I use (isset($_FILES['image']))


floridaflatlander

Recommended Posts

I have a multipart forum that can load a photo if needed.

 

My problem is that if no photo is selected for upload it deletes any data in the database for the current row if there is a photo.

 

What I'm trying todo is not load upload_thumb.inc.php if no photo is selected and not run the UPDATE query

 

 // If everything's Okay Process the whole form

if (empty($errors)) { 

//Run some of the script here

if (isset($_FILES['image'])) { // Upload thumb if one is selected
include_once ('../includes/upload_thumb.inc.php');

// run UPDATE query script to insert photo location and stuff in db

}

// run more script here

}

 

What's happening if I have a photo and don't upload another photo the guery over writes the db info for the current photo.

 

The idea with isset($_FILES['image']) was to not load upload_thumb.inc.php and not to run the UPDATE script

 

Thanks

S

Link to comment
Share on other sites

one idea what you could do is use php's getimagesize function to test more thouroughly for an image upload

 

 

<?php
$size = getimagesize($filename);
$fp = fopen($filename, "rb");
if ($size && $fp) {
    // do upload here
} else {
    // do nothings or something else
}
?>

 

 

 

 

Link to comment
Share on other sites

Thanks for the reply

 

The idea is for upload_thumb.inc.php not to be uploaded if I don't need it.

 

I already have a jury rigged condition almost like your talking about it's

 

if (isset($_FILES['image'])) { // Upload thumb if one is selected
include_once ('../includes/upload_thumb.inc.php');

if($thumb_name) {
run update query
}
}

 

Thanks again

Link to comment
Share on other sites

 

if (isset($_FILES['image']) && $_FILES['image']['error'] == UPLOAD_ERR_OK){
   //a file was uploaded, run your include/update
}

 

That will only run the include file if a file was successfully uploaded.  If you are doing additional validation checks inside your include file (file type, size, dimensions, etc) then you'll need a flag to indicate success of failure of that. 

 

 

Link to comment
Share on other sites

 

if (isset($_FILES['image']) && $_FILES['image']['error'] == UPLOAD_ERR_OK){
   //a file was uploaded, run your include/update
}

 

As a note it's include/"upload_thumb.php" not update <<< upload_thumb.php uploads a photo, does the checks, resizes it and sizes it to a file

 

I'm not uploading a file, this is a muiltipart form that I use to edit and upload a photo if I want to, in this case I don't want to upload a file. but I do want to edit other text info.

// If everything's Okay Process the whole form
if (empty($errors)) {
//Run some of the script here
// If I decide to upload a photo with  name="image" this if will execute includes/upload_thumb.inc.php *** If I don't selesct a photo this if is bypassed
if (isset($_FILES['image']))
{ // Upload thumb if one is selected
include_once ('../includes/upload_thumb.inc.php');
// run UPDATE query script to insert photo location and stuff in db
}
// run more script here
}

 

I'll have to think about it because $_FILES['image']['error'] == UPLOAD_ERR_OK assumes I want to or have uploaded a photo, I think

Link to comment
Share on other sites

Thanks

 

I've played with - if (isset($_FILES['image']) && ($_FILES['image']['error'] == UPLOAD_ERR_OK)) - from several angles and that may have done it. I think this is like error 4, no file uploaded

 

I'll come back tomorrow and give an update after I play with it for a while.

 

I don't under stand why (isset($_POST['news_info'])) && (isset($_FILES['image'])) are different, but I'll address that later, anyway thanks again.

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.