Jump to content

$_FILES help


noclist

Recommended Posts

How do I determine if

$_FILES['thumbNail']['name']

is blank?

 

I am uploading images into a folder on my server called thumbNail and I would like to specify a default image (noimage.gif) if no prior image has been uploaded, but I'm having trouble getting an if statement to register true if the image upload was skipped. Thank you.

Link to comment
Share on other sites

if (!isset($_FILES['thumbNail']['name']))
{
$thumbNail="thumbNail/noimage.gif";
}

 

Is something like that how I would check if there is a value already?

Then obviously I'm trying to assign noimage.gif if there is no value.

 

Yes, but to make it make sense you need to do this

if (!isset($_FILES['thumbNail']['name']))

{

$thumbNail="thumbNail/noimage.gif";

}else{

$thumbNail=$_FILES['thumbNail']['name'];

}

 

So you keep using the same variable. (I'd switch the order of the if/else and use isset() instead of !isset() personally)

Link to comment
Share on other sites

Okay, looks like it is verifying correctly, but I'm still having trouble assigning the default image.

 

It turns out the folder I was uploading to is called movieThumbs, not thumbNail...

 

	if (isset($_FILES['thumbNail']['name']))
{
$thumbNail = $_FILES['thumbNail']['name'];
}
else
{
$thumbNail="movieThumbs/noimage.gif";
}

 

Leaving the thumbnail field blank still results in a broken image linking to just the movieThumbs/ directory.

Link to comment
Share on other sites

Your code needs to test the $_FILES['thumbNail']['error'] element to determine if an actual file was successfully uploaded, because the ['name'] element will be set to a value for several of the possible upload errors.

Great answer :)  :thumb-up:

Link to comment
Share on other sites

Using this method...

 

if($_FILES['userfile']['error']==0) {

  // process

} else {

  // handle the error

}

 

	if($_FILES['thumbNail']['error']==0) 
{
  	$thumbNail = $_FILES['thumbNail']['name'];
} 
else 
{
$thumbNail="movieThumbs/noimage.gif";
}

 

Still having the same issue. I must be doing something fundamentally wrong.

Link to comment
Share on other sites

Here is what echoes for thumbNail:

 

When I choose a thumbnail image to upload:

 

    [thumbNail] => Array

        (

            [name] => x.gif

            [type] => image/gif

            [tmp_name] => /var/tmp/phpXylX84

            [error] => 0

            => 6577

        )

 

When I leave the thumbnail field blank:

 

    [thumbNail] => Array

        (

            [name] =>

            [type] =>

            [tmp_name] =>

            [error] => 4

            => 0

        )

 

error 4 being no file uploaded, which is what I should see. I feel like I'm doing everything right except perhaps

 

	else 
{
$thumbNail="movieThumbs/noimage.gif";
}

 

Is that the correct way to assign the default image to that variable given my error 4?

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.