I have looked everywhere for an answer to this and implemented lots of different code but none of it works...
I am trying to upload a document to mysql without success. The name, size and file type all upload fine but the content is still a null value. When the file downloads, it is blank for the case of text documents and corrupted in the case of pdfs (although I think that is the way acrobat displays empty files).
Here is the upload form:
Code: Select all
echo "<form action='adviserchange.php?number=$a' method='post' enctype='multipart/form-data'>";
.
.
.
<input type='hidden' name='MAX_FILE_SIZE' value='160000000'>
<input name='userfile' type='file' id='userfile'>
</td>
<td width='80'></td>
</tr>
</table>
</td></tr>";
echo "</table>";
echo "<input type='hidden' name='id' value='$a' />";
echo "<input type='submit' value='Submit' /></form>";Here is the upload php:
Code: Select all
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$fp = fopen($tmpName, 'r');
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}
$query = "UPDATE current SET docname='$fileName', docsize='$fileSize', doctype='$fileType', doccontent='$content' WHERE ida = '".$a."'";
mysql_query($query) or die('Error, query failed');
echo "<br /><br />File $fileName uploaded <br />";[img] [/img]
I hope that image works here.
I am completely at a loss. I have set all permissions for all users (temporarily), could it be other securities? Perhaps to do with the fact that I'm using IIS and php together.
If someone could pinpoint the problem I'd be massively grateful.
Thanks
P.S. it should definitely be ida and not docid as the mysql field.