Associate
- Joined
- 18 Oct 2002
- Posts
- 152
- Location
- brighton beach :)
Hi all, I have a simple file upload for an image. Form code:
And my PHP code:
The problem is the $_FILES is empty ("array()" when print_r'd). I have uploads set, max filesize is 2Mb. I have no idea why? If anyone can help me I'd really appreciate it.
Code:
<form method="post" action="photograph.php" enctype="mulitpart/form-data">
<input type="hidden" name="ID" value="<? echo $_GET[id]; ?>" />
<table>
<tr>
<td> Select photograph: </td>
<td><input type="file" name="photograph" id="photograph" />
</td>
</tr>
<tr>
<td> Caption: </td>
<td><input type="text" name="caption" />
</td>
</tr>
<tr>
<td></td>
<td><input type="submit" value=<? if ($_SESSION['user_username']){ ?>"submit photograph"<? } else { ?>"please login to add a photograph" disabled="disabled"<? } ?> />
</td>
</tr>
</table>
</form>
And my PHP code:
Code:
//get last image filename from the MAX ID
$result = mysql_query("SELECT MAX(ID) as 'MaxID' FROM Photos");
while ($current = mysql_fetch_array($result, MYSQL_ASSOC)){
$file_num = $current[MaxID] + 1;
}
// Get the image
$imageTMP = $_FILES['photograph']['tmp_name'];
$name = $_FILES['userfile']['name'];
$size = $_FILES['photograph']['size'];
if(move_uploaded_file($imageTMP, 'photos/$file_num.jpg')){
// Insert photo into database
mysql_query("INSERT INTO Photos (BusinessID, Username, Filename, Date, Caption) VALUES ($_POST[ID], '$_SESSION[user_username]', '$file_num.jpg', '".date("m/d/Y")."' , '$_POST[caption]')");
//redirect back to the page
header("location:business.php?id=$_POST[ID]");
} else {
print_r($_FILES);
echo "<br />File could not be uploaded. This may be because your file is too big. Please click back and try again.";
echo "<br />File name: ".$name;
echo "<br />File size: ".$size;
phpinfo();
}
The problem is the $_FILES is empty ("array()" when print_r'd). I have uploads set, max filesize is 2Mb. I have no idea why? If anyone can help me I'd really appreciate it.