Jump to content

Upload pdf to existing record in MySQL.


Shafotti

Recommended Posts

Hello all, I'm a noobie but learning a lot. This is my first ever post to a forum so I'm unsure of protocal/terminology/etiquette/etc. Advice on that is welcome.

 

I have a project where I need to take a spreadsheet loaded with PC inventory information and import it into MySQL. No problem. That was easy. Also, I need to get the pdf of the invoices and upload those to the database. It was a little more work and research but I figured out how to do that. Here's my problem. I need to upload these pdf's and match them with there existing records. So far, all I've been able to do is add entries to the end of the DB. Can anybody help?

 

Here is my code for a working upload. How can I alter it to edit an existing record? If the answer is way too involved to post, please point me in the right direction. Much thanks in advance!

 

<form method="post" enctype="multipart/form-data">

<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">

<tr>

<td width="246">

<input type="hidden" name="MAX_FILE_SIZE" value="2000000">

<input name="userfile" type="file" id="userfile">

</td>

<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>

</tr>

</table>

</form>

<?php

if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0)

{

$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);

}

 

include 'config.php';

include 'opendb.php';

 

$query = "INSERT INTO list (name, size, type, content ) ".

"VALUES ('$fileName', '$fileSize', '$fileType', '$content')";

 

mysql_query($query) or die('Error, query failed');

include 'closedb.php';

 

echo "<br>File $fileName uploaded<br>";

}

?>

Link to comment
https://forums.phpfreaks.com/topic/82055-upload-pdf-to-existing-record-in-mysql/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.