[thelist] uploading binaries in php/mysql

Sasha Sklar! spyrral at hotmail.com
Tue Mar 5 17:34:01 CST 2002


>>Hey everyone, quick question. I've been doing a bit of
>>experimentation/programing using a members.evolt.org account. I've been
>>trying to store and serve images from the mysql database using php, and
>>for
>>some reason I can't seem to get at the files after they are uploaded.
>
>[...]
>
>>Any ideas?
>
>Hi,
>
>Can you show us a snippet of the code you're using to move the file?
>
>Cheers
>Andrew

Ladies and gentlemen, the code:

<?php
// get the nessesary includes
include '../includes/database.php';


if ($submit == "upload")
{

  // Get the file and prepare it for insertion into the database
  $strData = addslashes(fread(fopen($_FILES['userfile']['tmp_name'], "r"),
filesize($_FILES['userfile']['tmp_name']))) or die("Could not open file.");

  $strSQLQuery = "INSERT INTO images
(description,image,filename,filesize,filetype) ";
  $strSQLQuery .= "VALUES
('$form_description','$strData','$_FILES['image']['name']','$_FILES['image']['size']','$_FILES['image']['type']')";

  $pResult = mysql_query($strSQLQuery, $dbConnect);

  $id= mysql_insert_id();
  if (isset($image) && $image != "none")
  {
    print "<p>This file has the following Database ID: <b>$id</b>";
  }
  else
  {
    echo "<p>Failed to insert file into database.";
  }

}

?>
<html>

<head>

<title>Image Upload</title>

</head>

<body>

<form enctype='multipart/form-data' action='<?php echo $PHP_SELF; ?>'
method='post'>
<input type='hidden' name='MAX_FILE_SIZE' value='1000000'>
<input type="text" name="form_description"  size="40">
Send this file: <input name='image' type='file'>
<input type='submit' name='submit' value='upload'>
</form>

</body>

</html>

Its basically taken straight out of a tutorial I found on phpbuilder.com



_________________________________________________________________
MSN Photos is the easiest way to share and print your photos:
http://photos.msn.com/support/worldwide.aspx




More information about the thelist mailing list