if (isset....) problem. urgently need help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Think Pink
Forum Contributor
Posts: 106
Joined: Mon Aug 02, 2004 3:29 pm

if (isset....) problem. urgently need help

Post by Think Pink »

hello,
Pls urgently need help

I have something like this but is not working

Code: Select all

<?php
if (isset($_FILES['file']['name'])) {
$nume_poza = $_FILES['file']['name'];
}
else {
$nume_poza = "no_picture.gif";
}
?>
what i want to do is to see if a picture was sent in the form. If the picture was sent, I capture the name of the picture, if no picture was sent, then I want to add to db the "no_picture.gif"
can I do that? how?
pls help
thx
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

try using [php_man]var_export[/php_man] on $_FILES
murthy
Forum Commoner
Posts: 50
Joined: Fri Aug 20, 2004 1:22 am
Location: India
Contact:

Post by murthy »

Hi,

use like this ::: empty()-- function
User avatar
Think Pink
Forum Contributor
Posts: 106
Joined: Mon Aug 02, 2004 3:29 pm

if (isset....) problem. urgently need help

Post by Think Pink »

thx 4 the urgently help
now I have another problem.
if the file is set it enters the name in the db, but if the file isn't set, it doesn't inserts the "no_picture.gif"
why?
User avatar
neophyte
DevNet Resident
Posts: 1537
Joined: Tue Jan 20, 2004 4:58 pm
Location: Minnesota

dunno but you could try this...

Post by neophyte »

Set up the conditions for getting no_picture.gif and then print the variable to the screen to see if your getting the result you want. This will help to determine where the variable is getting lost. You might also try replacing isset() with !empty() and see what happens....

Code: Select all

<?php
if (!empty($_FILES['file']['name'])) {
$nume_poza = $_FILES['file']['name'];
}
else {
$nume_poza = "no_picture.gif";
}
echo $nume_poza;
?>
n00bie to n00bie
User avatar
Think Pink
Forum Contributor
Posts: 106
Joined: Mon Aug 02, 2004 3:29 pm

Post by Think Pink »

is working now
thx
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

really lazy

Post by phpScott »

or you can be really lazy and set up the default in the db to be no_picture.gif.

:D
bubbleboy22
Forum Newbie
Posts: 3
Joined: Sun Sep 26, 2004 8:54 pm
Location: Colorado

Post by bubbleboy22 »

I am having a similar issue, but not quite.

What I think is happening is that the $_Files array is not getting "unset", so that if I try to use the same script/page it thinks the the $_Files array is set even though not from the last post.

So, my !empty() is reading as, well, !empty, when it should be.

How do I "unset" $_Files arrays? so that I can continue to use the same script/page for multiple records?

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

I've never seen the $_FILES array keeping data around without me asking it to by posting the same thing again. Maybe you could post your code?
bubbleboy22
Forum Newbie
Posts: 3
Joined: Sun Sep 26, 2004 8:54 pm
Location: Colorado

Post by bubbleboy22 »

Here's the whole block that's supposed to do the file move and add the name to a table on the condition that there's something to do. Right now it puts "" in the table if noone sets the file form box, essentially wiping out what was previously there.

thanks

Code: Select all

if (!empty ($_FILES&#1111;'logo']))&#123;
	move_uploaded_file($_FILES&#1111;'logo']&#1111;'tmp_name'], $imagefile);
	$updateFile = sprintf("UPDATE teams SET logo=%s WHERE team_id=%s",
			GetSQLValueString($_FILES&#1111;'logo']&#1111;'name'], "text"),
            GetSQLValueString($_POST&#1111;'team_id'], "int"));
	mysql_select_db($database_euro, $euro);
  $Result2 = mysql_query($updateFile, $euro) or die(mysql_error());
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the $_FILES['logo'] will never be empty.. it just won't contain file information. You may want to look at the error code, or see if the temporary name is empty instead. :)
bubbleboy22
Forum Newbie
Posts: 3
Joined: Sun Sep 26, 2004 8:54 pm
Location: Colorado

Post by bubbleboy22 »

That did it! Thanks! - SuperNoob

For anyone else with similar issues, this works with !empty() only and not isset.
Post Reply