Page 1 of 1
if (isset....) problem. urgently need help
Posted: Mon Sep 20, 2004 7:46 pm
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
Posted: Mon Sep 20, 2004 7:49 pm
by feyd
try using [php_man]var_export[/php_man] on $_FILES
Posted: Mon Sep 20, 2004 7:50 pm
by murthy
Hi,
use like this ::: empty()-- function
if (isset....) problem. urgently need help
Posted: Mon Sep 20, 2004 8:26 pm
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?
dunno but you could try this...
Posted: Mon Sep 20, 2004 8:49 pm
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
Posted: Tue Sep 21, 2004 8:10 am
by Think Pink
is working now
thx
really lazy
Posted: Tue Sep 21, 2004 8:56 am
by phpScott
or you can be really lazy and set up the default in the db to be no_picture.gif.

Posted: Sun Sep 26, 2004 8:59 pm
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
Posted: Sun Sep 26, 2004 9:03 pm
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?
Posted: Sun Sep 26, 2004 9:10 pm
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ї'logo'])){
move_uploaded_file($_FILESї'logo']ї'tmp_name'], $imagefile);
$updateFile = sprintf("UPDATE teams SET logo=%s WHERE team_id=%s",
GetSQLValueString($_FILESї'logo']ї'name'], "text"),
GetSQLValueString($_POSTї'team_id'], "int"));
mysql_select_db($database_euro, $euro);
$Result2 = mysql_query($updateFile, $euro) or die(mysql_error());
Posted: Sun Sep 26, 2004 9:13 pm
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.

Posted: Sun Sep 26, 2004 9:25 pm
by bubbleboy22
That did it! Thanks! - SuperNoob
For anyone else with similar issues, this works with !empty() only and not isset.