I have Apache2/mySQL 3.23.39/PHP4 installed on my home computer (Dell inspirion 8200 laptop, 512Mb ram, 1.8Mhz intell) for php debugging purposes. I am having a problem with file uploads. I create a form with a file upload field, but the file doesn't seem to be passes to the script. File uploads are enabled in the php.ini file. Below is the actual script with the error messages. Any help would be appreciated.
Script OutputPHP Code:<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<?php
function randomString($len) {
srand(date("s"));
$possible="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890";
$str="";
while(strlen($str)<$len) {
$str.=substr($possible,(rand()%(strlen($possible))),1);
}
return $str;
}
mysql_connect('localhost');
mysql_select_db('alumni');
if(isset($HTTP_POST_VARS[submit]))
{
echo "size: ".$HTTP_POST_VARS[userfile_size];
do
{
$name = randomString(5).strstr('$HTTP_POST_VARS[userfile_name]',".");
$result = mysql_query("SELECT filename from photos where filename = '$name'");
} while(mysql_num_rows($result) > 0);
$path = "/photos/".$name;
echo "PATH: ".$path."<BR><BR>";
copy($HTTP_POST_VARS[userfile], $path);
mysql_query("INSERT into photos values(NULL, '$HTTP_POST_VARS[name]', NULL, '$HTTP_POST_VARS[description]', '$name', '$name')") or die("UNABLE TO ADD SQL ENTRY:".mysql_error());
echo "copy successful!";
}
?>
<body bgcolor="#FFFFFF" text="#000000">
<form action="<?php echo $_SERVER[PHP_SELF]; ?>" method="post" enctype="multipart/form-data">
<table width="31%" border="1">
<tr>
<td width="27%">Your Name: </td>
<td width="4%"> </td>
<td width="69%">
<?php echo $uname; ?><input type="hidden" name="<? echo $uname; ?>" value="garret">
</td>
</tr>
<tr>
<td width="27%"> </td>
<td width="4%"> </td>
<td width="69%"> </td>
</tr>
<tr>
<td width="27%">Today's Date:</td>
<td width="4%"> </td>
<td width="69%">
<?php echo date("l: F j, Y"); ?>
</td>
</tr>
<tr>
<td width="27%"> </td>
<td width="4%"> </td>
<td width="69%"> </td>
</tr>
<tr>
<td width="27%">Description</td>
<td width="4%"> </td>
<td width="69%">
<textarea name="description" cols="30" rows="5"></textarea>
</td>
</tr>
<tr>
<td width="27%"> </td>
<td width="4%"> </td>
<td width="69%"> </td>
</tr>
<tr>
<td width="27%">Photo File:</td>
<td width="4%"> </td>
<td width="69%">
<input type="file" name="userfile" size="30">
</td>
</tr>
<tr>
<td colspan="3">
<div align="center">
<input type="submit" name="submit" value="Submit">
<input type="reset" name="Submit2" value="Reset">
</div>
</td>
</tr>
</table>
</form>
</body>
</html>
---------------------
size: PATH: /photos/7Xsni
Warning: Unable to open '' for reading: Permission denied in C:\Apache\Apache2\htdocs\photouploader.php on line 30







Bookmarks