You are here: uploading images to mysql « PHP SQL « IT news, forums, messages
uploading images to mysql

Posted by Gerard P Shea on 03/25/07 07:23

Hi all,

Can anyone give me a definitive answer as to how to successfully upload an
image to a MySQL database using php. I have tried numerous variations but
they all seem to produce the same errors. Following is the code I am
currently using:

<?php
$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);
}

mysql_connect("localhost", "user", "password") or die(mysql_error());
mysql_select_db("database") or die(mysql_error());
$query = "INSERT INTO uploads (filename, filesize, filetype, data) VALUES
('$fileName', '$fileSize', '$fileType', '$content')";

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

Whenever I run this code something gets stored in the database but there is
no name, size or type stored... just something in the data field.

If I print/echo the relevant $_FILES variables the file name is correct but
there is nothing printed for the size or type.

Any idea where I am going wrong? Any error in the coding (no errors are
produced as such)? Anything I need to adjust in the php or mysql config
files?

I am running php 4.4.6, IIS and MySQL.

Any ideas or suggestions would be greatly appreciated.

Thanks in advance.

Schmalz.

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация