UseBB Community

The official board for UseBB help and discussion

UseBB Community » 1.0 Discussion » file inputs

file inputs

Page: 1

Author Post
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??
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'];
Developer
Registered: Apr 2004
Posts: 2202
Location: Belgium
I guess that won't help, undefined index means that value does not exist.
_______________
--Dietrich (developer)
UseBB roadmap, dev mailing list & weblog
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...
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>
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".
_______________
--Dietrich (developer)
UseBB roadmap, dev mailing list & weblog
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.
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...

Page: 1

UseBB Community » 1.0 Discussion » file inputs

UseBB Community is powered by UseBB 1 Forum Software