Hi everyone, I've been stuck with this problem for a while now, and I really can't figure out what's going on; the script is simple: get a file from the user through the web form, upload the file to whatever the tmp directory is, read the file, insert the contents into the database...
Here is the script code [upload.php]
<?php
if(isset($_POST[go])) {
if(!empty($_FILES['pdf_file']['name']) && $_FILES['pdf_file']['type'] == "application/pdf") {
$file_name = $_FILES['pdf_file']['tmp_name'];
$instr = fopen($file_name, "rb");
$file_image = mysql_real_escape_string(fread($instr,filesize($file_name)));
$connect = @mysql_connect("localhost", "XlocalYuserZ", "UsersPassWord");
$select_db = @mysql_select_db("DbName", $connect);
$query = mysql_query("INSERT INTO files_tbl (pdf_file) VALUES('" . $file_image ."')");
fclose($instr);
} else {
?>
<p>Not a valid file!</p>
<?php
}
?>
<p>File uploaded correctly.</p>
<?php
}
?>
<div style="width:735px">
<form method="post" action="upload.php" class="page_form" enctype="multipart/form-data">
<fieldset><legend>Upload file</legend>
<table border="0" cellpadding="3" cellspacing="1" style="width:700px;">
<tr>
<td class="left_middle"><label for="pdf_file">PDF File to upload:</label></td>
<td class="right_middle"><input type="file" name="pdf_file" id="pdf_file" class="txt_common" /></td>
</tr>
<tr>
<td colspan="2" class="right_middle"><input type="submit" name="submit" value="Upload to Database" class="button" /></td>
</tr>
</table>
<input type="hidden" name="go" value="1" />
</fieldset>
</form>
</div>
The code is pretty straight-forward, as you can see; it does not work however and I've been unable to find out why. It seems to upload some times, some others not, which is weird, but it might just be the server messing around with me... hehe... I have already granted 775 permissions on this PHP file.
All the script does is hang forever, it happens with any web browser, no error messages, nothing...
I hope some of you guys can give me a hand; I've been using Google in order to find related problems but it's not been enough... maybe apache permissions? .htaccess files? I truly don't know what to try.
Regards,
-
Javier