shamuraq Posted May 22, 2011 Share Posted May 22, 2011 Hi guys, This is my first time to insert PDF into MySQL BLOB. Below is my form that i used <?php <form enctype="multipart/form-data" name="frmUploadFile" action="ulf-exec.php" method="post"> <select name="title" id="title"> <option>xxx</option> <option>yyy</option> <option>zzz</option> </select> </label> <input name="des" type="text" class="dropdownlists1" id="des"></td> <input name="fileUpload" type="file" class="dropdownlists1" id="fileUpload" size="20" border=""></td> <input type="submit" name="button" id="button" value="Submit"> </form> ?> I have prepared my database based on the required but decided to test with echo just to confirm there's no issue with the code The action="ulf-exec.php" : <?php function clean($str) { $str = @trim($str); if(get_magic_quotes_gpc()) { $str = stripslashes($str); } return mysql_real_escape_string($str); } //Sanitize the POST values $title = clean($_POST['title']); $des = clean($_POST['des']); $fileUpload = $_POST['fileUpload']; if(empty($des) || $fileUpload == "none") die("You must enter both a description and file"); $fileHandle = fopen($fileUpload, "r"); $fileContent = fread($fileHandle, $fileUpload_size); $fileContent = addslashes($fileContent); $date = date('d').'-'.date('m').'-'.date('y'); $time = date('h').':'.date('i').':'.date('s'); echo "<h1>File Uploaded</h1>"; echo "The details of the uploaded file are shown below:<br><br>"; echo "<b>File name:</b> $fileUpload_name <br>"; echo "<b>File type:</b> $fileUpload_type <br>"; echo "<b>File size:</b> $fileUpload_size <br>"; echo "<b>Uploaded to:</b> $fileUpload <br><br>"; echo "<a href='uploadfile.php'>Add Another File</a>"; ?> This is the error: Warning: fopen() [function.fopen]: Filename cannot be empty in /ulf-exec.php on line 30 Warning: fread(): supplied argument is not a valid stream resource in ulf-exec.php on line 31 Quote Link to comment https://forums.phpfreaks.com/topic/237117-php-mysql-inserting-of-pdf-into-blob/ Share on other sites More sharing options...
Rifts Posted May 22, 2011 Share Posted May 22, 2011 I don't think you can read a pdf with php. I believe you need something like this http://www.fpdf.org/ Quote Link to comment https://forums.phpfreaks.com/topic/237117-php-mysql-inserting-of-pdf-into-blob/#findComment-1218710 Share on other sites More sharing options...
Pikachu2000 Posted May 22, 2011 Share Posted May 22, 2011 The filetype has nothing to do with the error. The problem is that this: $fileUpload = $_POST['fileUpload']; references an array index that doesn't exist. The data related to the file will be in the $_FILES array, not the $_POST array. Add the following at the top of the ulf-exec.php script to see the structure of both arrays: echo '<pre>'; print_r($_POST); print_r($_FILES); echo '</pre>'; Quote Link to comment https://forums.phpfreaks.com/topic/237117-php-mysql-inserting-of-pdf-into-blob/#findComment-1218716 Share on other sites More sharing options...
shamuraq Posted May 23, 2011 Author Share Posted May 23, 2011 I don't think you can read a pdf with php. I believe you need something like this http://www.fpdf.org/ No... i dun want php to read the pdf... Just want php to insert my pdf's into mysql blob... Quote Link to comment https://forums.phpfreaks.com/topic/237117-php-mysql-inserting-of-pdf-into-blob/#findComment-1218941 Share on other sites More sharing options...
shamuraq Posted May 23, 2011 Author Share Posted May 23, 2011 The filetype has nothing to do with the error. The problem is that this: $fileUpload = $_POST['fileUpload']; references an array index that doesn't exist. The data related to the file will be in the $_FILES array, not the $_POST array. Add the following at the top of the ulf-exec.php script to see the structure of both arrays: echo '<pre>'; print_r($_POST); print_r($_FILES); echo '</pre>'; Thanx Pikachu... solved it... but its not over yet... i now need to script the streaming of the pdf from server... Is there anyway we can calculate the max the pdf size should be to avoid straining the server? Quote Link to comment https://forums.phpfreaks.com/topic/237117-php-mysql-inserting-of-pdf-into-blob/#findComment-1218964 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.