homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

mysql file upload

 7:27 pm on Feb 19, 2008 (gmt 0)

Ok Im trying to upload files and have them stored in a table on mah database, but its not working out at all. I've been trying the whole day and can't get anything to work. Here is my code:

<h3>Please Choose a File and click Submit</h3>

<form enctype="multipart/form-data" action="" method="post">
<input name="userfile[]" type="file" />
<input type="submit" value="Submit" />


// the upload function
function upload(){

if(is_uploaded_file($_FILES['userfile']['tmp_name'])) {

// prepare the image for insertion
$imgData =addslashes (file_get_contents($_FILES['userfile']['tmp_name']));
// $imgData = addslashes($_FILES['userfile']);

// get the image info..
$size = getimagesize($_FILES['userfile']['tmp_name']);

// put the image in the db...
// database connection
mysql_connect($mysql_server, $mysql_user, $mysql_password) OR DIE (mysql_error());

// select the db
mysql_select_db ("database") OR DIE ("Unable to select db".mysql_error());

// our sql query
$sql = "INSERT INTO test
( image_id , image_type ,image, image_size, image_name)
('', '{$size['mime']}', '{$imgData}', '{$size[3]}', '{$_FILES['userfile']['name']}')";

// insert the image
if(!mysql_query($sql)) {
echo 'Unable to upload file';



 7:30 pm on Feb 19, 2008 (gmt 0)

Are you getting any errors or is it just not inserting anything and not erroring?


 7:39 pm on Feb 19, 2008 (gmt 0)


i hope this help

$imgData =addslashes (file_get_contents($_FILES['userfile']['tmp_name']));


$tempfile = fopen($_FILES['userfile']['tmp_name'],'rb');
$filedata = fread($tempfile,filesize($uploadfile));
$imgData = addslashes($filedata);

if no work please post the error

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved