I have taken this routinw from a book "PHP and MYSQL" and tailoured it just a little. The problem is that the form (see below) allows me to select a file, but when I go to process the form (see below) I always get the nofile specified. What ever I do. Any help would be appreciated - even a pointer to a totally different example would be OK.
<?
############################################
Module : admin_file_upload_form.php
Who When What
#
############################################
include("inc_stylesheet.inc");
include("inc_get_params.inc");
if ((($app_id == "") or ($app_id=="999999999")))
{
echo "<p>No application currently chosen</p> \n";
exit;
}
?>
<body class=admin>
<h1>File Upload</h1>
<form enctype="multipart/form-data" action="admin_file_upload_process.php" method=post>
<input type="hidden" name="MAX_FILE_SIZE" value="1000">
<input type="hidden" name="app_id" value="<?echo $app_id ?>">
<table cellspacing=0 width="100%">
<tr>
<td class="admin_body">File to upload: </td>
<td class="admin_body"><input name="userfile" type="file" ></td>
</tr>
</table>
<br>
<input type="submit"value="Upload">
</form>
</body>
<?
############################################
Module : admin_view_images.php
Who When What
#
############################################
include("inc_get_params.inc");
include("inc_stylesheet.inc");
?>
<head>
<title>Uploading...</title>
</head>
<body>
<p><b>Loading File...</b></p>
<?
$current_dir="./img/".$app_id."/";
#this is in here are there is a bug with is_dir
error_reporting(0);
#if the directory does not exist then make sure it does.
if (!is_dir($current_dir))
{
mkdir($current_dir,0777);
}
error_reporting (E_ALL);
echo "user_file:".$userfile."<br>\n";
if ($userfile=="none")
{
echo "here-1<br>";
echo "no file uploaded";
exit;
}
if ($userfile_size==0)
{
echo "zero length";
exit;
}
if (!is_uploaded_file($userfile))
{
echo "upload atatck";
exit;
}
if ((strpos(strtolower($userfile_name),'.jpg') <= 0) or
(strpos(strtolower($userfile_name),'.gif') <= 0) or
(strpos(strtolower($userfile_name),'.bmp') <= 0))
{
echo "Not an Image file. Only files of type JPEG, GIF or BMP allowed. Try again.";
exit;
}
$upfile = $current_dir.$userfile_name;
if (!copy($userfile, $upfile))
{
echo "could not find directory";
exit;
}
echo "<p></b>file uploaded successfully</b></p><br><br>";
$fp = fopen($upfile,"r");
$contents = fread($fp, filesize($upfile));
fclose($fp);
$content = strip_tags($contents);
$fp = fopen($upfile, "w");
fwrite($fp, $contents);
fclose($fp);
?>
</body>