Page 1 of 1

PHp: image display problem !

Posted: Wed May 26, 2010 2:29 pm
by tamim
<html>
<head><title>File Upload To Database</title></head>
<body>
<h3>Please Choose a File and click Submit</h3>

<form enctype="multipart/form-data" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
<input name="userfile" type="file" />

<input type="submit" value="Submit" />
</form>
</body>
</html>

<?php

if(!isset($_FILES['userfile'])) {
echo '<p>Please select a file</p>';
}
else
{
try {
upload();

echo '<p>Thank you for submitting</p>';
}
catch(Exception $e) {
echo $e->getMessage();
echo 'Sorry, could not upload file';
}
}
function upload(){

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

$con=mysql_connect("localhost", "root", "") OR DIE (mysql_error());


mysql_select_db ("rafi") OR DIE ("Unable to select db".mysql_error());
if($_FILES['userfile']['size'] < 100000000)
{

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



$size = getimagesize($_FILES['userfile']['tmp_name']);




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

if(!mysql_query($sql)) {
echo 'Unable to upload file';
}
}
}
else {
echo
'<div>File exceeds the Maximum File limit</div>
<div>Maximum File limit is <div>
<div>File '.$_FILES['userfile']['name'].' is '.$_FILES['userfile']['size'].' bytes</div>
<hr />';
}
}

error_reporting(E_ALL);



$sql =("select image FROM testblob WHERE image_id=0 ");
$result = mysql_query($sql);
echo mysql_result($result, 0);


?>


This is my script , when i upload any image its display in binary plz help me out !

Re: PHp: image display problem !

Posted: Wed May 26, 2010 3:51 pm
by requinix
If the problem is with displaying then perhaps you should post the display script USING CODE HIGHLIGHTING.

Code: Select all

[syntax=php][/syntax]