Skip to main content
September 17, 2008
Question

File Upload issues

  • September 17, 2008
  • 1 reply
  • 258 views
There is a file upload that I have and I am getting an error...
Notice: Undefined variable: file_list in C:\vhosts\mysite\upload\index.php on line 20
On line 20 in my php page happens to be the following code that is giving an error...$file_list .= "<option value=\"$file\" >$file</option>";


<?php
#for windows...
$dirname = $_SERVER['DOCUMENT_ROOT'].'/_assets/professor/';
//$dirname = "C:\\wamp\\www";

#(for Linux... $dirname = "user/local/apache/bin";)

$dir = opendir($dirname);

while(false != ($file = readdir($dir))){
if(($file != ".") and ($file != "..")){
$file_list .= "<option value=\"$file\" >$file</option>";
}
}
closedir($dir);
?>

This is what is in the body...
<form enctype="multipart/form-data" action="uploaded.php" method="POST">
<fieldset><legend>Upload Professor Image</legend>
<!-- MAX_FILE_SIZE must precede the file input field -->
<!--input type="hidden" name="MAX_FILE_SIZE" value="30000" /-->
<!-- Name of input element determines name in $_FILES array -->
Send this file: <input name="userfile" type="file" />
<div align="center"><input type="submit" value="Send File" /></div>
</fieldset>
</form>
<br>
<br>
<form action="delete.php" method="post">
<fieldset><legend>Delete Professor Image</legend>
<select name="deleteFile">
<?php echo($file_list); ?>
</select>
<div align="center"><input type="submit" name="go" value="Delete File"></div>
</fieldset>
This topic has been closed for replies.

1 reply

Inspiring
September 17, 2008
AdonaiEchad wrote:
> There is a file upload that I have and I am getting an error...
> Notice: Undefined variable: file_list in C:\vhosts\mysite\upload\index.php on
> line 20
> On line 20 in my php page happens to be the following code that is giving an
> error...$file_list .= "<option value=\"$file\" >$file</option>";

What that's telling you is that you're adding a value to a variable that
doesn't yet exist. In your case, it probably doesn't matter, but using
undefined variables is a potential security risk. To eliminate the
warning - and the risk - declare $file_list before using it:

$file_list = '';

--
David Powers, Adobe Community Expert
Author, "The Essential Guide to Dreamweaver CS3" (friends of ED)
Author, "PHP Solutions" (friends of ED)
http://foundationphp.com/