mxcnlink Posted December 7, 2009 Share Posted December 7, 2009 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 Quote Link to comment https://forums.phpfreaks.com/topic/184261-pdf-file-upload-to-mysql/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 7, 2009 Share Posted December 7, 2009 The code is pretty straight-forwardIt is too straight-forward, while it is checking for some of the possible errors (all at once so you don't know which one is failing) it is not checking for any where near all the possible errors. See this link for more error checking and error reporting ideas - http://www.phpfreaks.com/forums/index.php/topic,278952.msg1320835.html#msg1320835 Edit: and please remove the @ from in front of your mysql_ functions. Don't you suppose that if you were getting errors when you called those functions that you would want to know about them as they could be relevant to why your code is not doing what you expect? You should NEVER put @ in code to suppress errors. Quote Link to comment https://forums.phpfreaks.com/topic/184261-pdf-file-upload-to-mysql/#findComment-972762 Share on other sites More sharing options...
mxcnlink Posted December 7, 2009 Author Share Posted December 7, 2009 Thanks for the follow-up! I'm taking a look at your suggestions now. Regarding the "@" in the mysql statements: that's just because of a copy/paste from a production script, and for sampling the problem here... the script never does reach that far anyways, and I do have it without the "@" right now. I appreciate your help. I'll post again with my results. Quote Link to comment https://forums.phpfreaks.com/topic/184261-pdf-file-upload-to-mysql/#findComment-972936 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.