Page 1 of 1

Upload and Files tag

Posted: Thu Jul 11, 2002 1:36 pm
by aqwarium
Hello

i'm trying to make an upload interface with php.

the problem is that i can't give a deffault value to the file tag

the generated code is :
<input type="file" name=fic_img size="11" value="img.jpg">
but the value don't appear in the page !!!

who can help me ?
thanks[/url]

Posted: Thu Jul 11, 2002 1:57 pm
by RandomEngy
Just out of curiosity, why do you want to put a default value? You have no way of knowing what images are where on a user's computer.

Posted: Thu Jul 11, 2002 2:08 pm
by aqwarium
i try to use this field for two thinks :
- modify an existing mission file
- create a new mission

in case of a new mission, i don't know what is the name of the field

in case of a existing mission, i know the default value
if the user just change the name of the mission, i have to keep the name of the image
if the user change the picture, i have to upload his picture !

i don't want to use two fields... if possible !!! :roll:

Posted: Thu Jul 11, 2002 2:59 pm
by RandomEngy
Post your current code here. I'm really confused as to what's going on. I guess you are making some sort of game? Are you giving an option to upload a saved game file? Did you set up a database to keep this information?

Whatever you're trying to do, I'm completely certain that it can be done without needing a default value in the upload field, and would probably be better that way. Remember, an upload field takes the path of a file from the user's computer, such as "C:\gamefiles\mission2.msf" . If you don't know where the file is (you don't), there is no sense in putting a default value there.

Posted: Thu Jul 11, 2002 3:31 pm
by aqwarium
I've got a mission database
-French Title
-French Object
-English Title
-Eng obj
-Spain Title
-Spain Object
-Image (a text field whis the name without the server path)

the administrator of the site can :
- create new mission
so I have to upload the file and to write the name in the Image field
- modify an existing mission
in this case, i want to put the default value because the administrator will perhaps change only the description and not the image !!!

i send you a part of the code :

or ($index = 1 ; $index < $nbcol ; $index++)

{
printf('<font color="'.$body_text2.'" size="'.$body_size.'" face="'.$body_font.'"><b>');

if ($mis[$index]<>"Image :") {

printf($mis[$index]." ".'</b></font><input type="text" name="'.$nom[$index].'" size="27" value="'.$lig[$index].'"> </font><br>');

}
else {

printf($mis[$index]." ".'</b></font><input type="text" name="'.$nom[$index].'" size="27" value="'.$lig[$index].'"> </font><br>');

printf('<font color="'.$body_text.'" size="'.$body_size.'" face="'.$body_font.'"><b>');

// HERE IS THE PROBLEM :

$temp="<input type=\"file\" name=".$nom[$index]." size=\"11\" value=\"".$lig[$index]."\">";

}
$fichier=$lig[$index];


THE GENERATED RESULT :

<input type="file" name="TXT_IMG" size="11" value="Unesco.jpg">

If you find something...

Thanks

Ax

Posted: Thu Jul 11, 2002 3:57 pm
by RandomEngy
Ahh that's easy. Wherever you're sending this information, add a check for the file, something like:

Code: Select all

if ( $_FILES&#1111;'filename']&#1111;'size'] != 0 )
&#123;
  // update the file
&#125;
Leaving the field blank will result in no change to the mission file.

Posted: Thu Jul 11, 2002 4:13 pm
by aqwarium
Thanks for your help
but i don't really understand what you've explain !!!
i'm new in php/sql : 3 days and i've got many problem with the syntax.

why the default value is not simply loaded ???

Posted: Fri Jul 12, 2002 11:48 am
by RandomEngy
"file" fields work differently from other fields. They are meant for the user to enter the name of a file on thier computer, which the browser then sends to the server. The browser doesn't let you put a default value in, because it would be meaningless to everyone using it. Say you put the default value as "img.jpg" . If they press submit with that in there, no file would be sent, since there is not a file named "img.jpg" on their computer.

I hope you understand...

Posted: Sat Jul 13, 2002 10:24 am
by aqwarium
Yes it's ok !
Thanks for your help

Whatever, I've find another way to use it ![/url]