Jump to content

PHP -> MYSQL - Inserting of PDF into BLOB


shamuraq

Recommended Posts

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

Link to comment
Share on other sites

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>';

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.