[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
>>some reason I can't seem to get at the files after they are uploaded.
>>Any ideas?
>Can you show us a snippet of the code you're using to move the file?

Ladies and gentlemen, the code:

// 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

  $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>";
    echo "<p>Failed to insert file into database.";




<title>Image Upload</title>



<form enctype='multipart/form-data' action='<?php echo $PHP_SELF; ?>'
<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'>



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:

More information about the thelist mailing list