OK, I have some code where I'm trying to upload an image and copy it to a directory and then save the filename into a database. I have code in another part of my app that works exactly the same and it the same with the exception that it is in a different class. I cannot see why the $_FILES array is not being passed to the addBoardPost function because the code looks correct. I get the message that the file was NOT successfully uploaded even though I selected a file in the form.
I also tried using the $_FILES variable in the addBoardPost function with the same result.
Any ideas?
HTML Form in board_add template:
<form name="add" method="POST" action="board.php">
<input type="hidden" name="mode" value="add_post">
<table border=0 cellpadding=5 cellspacing=3>
<tr>
<td colspan=2>Post Category:</td>
</tr>
<tr>
<td colspan=2>Other form fields are above the File input</td>
</tr>
<tr>
<td colspan=2>Upload an image with your post.</td>
</tr>
<tr>
<td colspan="2">
<input type="file" name="logo" id="logo">
</td>
</tr>
<tr>
<td>
<input type="submit" value="Add Message"></td>
</tr>
</table>
</form>
This is the post action code in board.php:
if($_POST['mode'] == "add_post")
{
$result = $inventory->addBoardPost($_SESSION['user_id'], $_POST, $_FILES);
// show error messages based on $result
}
addBoardPost function in Inventory class:
public function addBoardPost($user_id, $data, $files)
{
if (isset($files['logo']))
{
echo "File ". $files['logo'] ." uploaded successfully.\n";
} else {
echo "File ". $files['logo'] ." NOT uploaded successfully.\n";
}
// Do other things with $data and the uploaded image
}