| Author |
Post |
|
|
#1 Sun Jul 16, 2006 7:42 pm
|
|
Moderator
Registered: Oct 2005
Posts: 437
Location: canada
|
Hey, I'm trying to grab a file from a form but it keeps telling me that its an undefined index: $filename = $_FILES['newfile']['name']; Quote E_NOTICE - Undefined index: newfile
I know it's probably just a placement error or something but i'm not sure??
|
|
|
#2 Sun Jul 16, 2006 8:41 pm
|
|
Member
Registered: Apr 2006
Posts: 54
Location: Athens, Greece
|
That's just a notice.. If you use the error control operator won't you do what you want? Sth like this: $filename = @$_FILES['newfile']['name'];
|
|
|
#3 Sun Jul 16, 2006 9:02 pm
|
|
Developer
Registered: Apr 2004
Posts: 2202
Location: Belgium
|
I guess that won't help, undefined index means that value does not exist.
|
|
|
#4 Sun Jul 16, 2006 10:35 pm
|
|
Member
Registered: Jul 2006
Posts: 37
Location: Goslar, Germany
|
Perhaps you are submitting a form with an empty file-element ? Often browsers do not send form-fields without a value... _______________ Talking is silver, writing is gold...
|
|
|
#5 Tue Jul 18, 2006 4:14 pm
|
|
Moderator
Registered: Oct 2005
Posts: 437
Location: canada
|
What do you mean by an empty file-element??? This is what i have: if ( !empty($newfile) ) { $filename = $_FILES['newfile']['name']; $ext = strrchr( $filename, '.' ); $file = $str . $ext; $uploadfile = $uploaddir . basename($file); $filesize = $_FILES['newfile']['size'] / 1024; $filesize = round($filesize, 1); $newfilen = $file; //move_uploaded_file($_FILES['newfile']['tmp_name'], $uploadfile) }
and this is my form <tr> <td class="fieldtitle">New File</td> <td><input type="file" name="newfile" /><p>Use this to replace an existing file. Just leave blank to keep the same file.</p></td> </tr> <tr>
|
|
|
#6 Tue Jul 18, 2006 7:12 pm
|
|
Developer
Registered: Apr 2004
Posts: 2202
Location: Belgium
|
I guess files just aren't parsed as "files" in PHP, probably because you don't use enctype="multipart/form-data".
|
|
|
#7 Tue Jul 18, 2006 7:43 pm
|
|
Moderator
Registered: Oct 2005
Posts: 437
Location: canada
|
Well the weird thing is i'm using basically the same thing in another area and that works fine. Naw, i do have the enctype type set.
|
|
|
#8 Tue Jul 18, 2006 8:24 pm
|
|
Member
Registered: Jul 2006
Posts: 37
Location: Goslar, Germany
|
My first thought was you might have a problem if no file is selected in the file-chooser. I had this problem with a not-checked checkbox. The browser doesn't send it with a zero-value, it doesn't send it at all. So checking for the filename could be a problem because it may not be empty but not set at all. But now I vote for the encoding type, too  _______________ Talking is silver, writing is gold...
|