A community in which webmasters can ask for help with topics such as PHP coding , MySQL , IT jobs, web design, IT security.
Current location:homephp forumphp talk in 2008 yearimage upload using php - page 1
User InfoPosts
image upload using php#1
I used this code to upload the picture. I got this code from stackoverflow. I am still unable to upload the image. I changed the db connection settings in table settings 2. I made the table but I am not sure whether the properties of the table I created are correct.

<html>
<head><title>Store Some Binary File to a DB</title></head>
<body>

<?php
if ($submit) {
$conn = mysql_connect("localhost", "your_username", "your_password")
or die ("Error connecting to database.");

mysql_select_db("your_database", $conn)
or die ("error connecting to database.");

$data = addslashes(file_get_contents($_FILES['form_data']['tmp_name'])


$result = mysql_query ("INSERT INTO your_table ".
"(description,bin_data,filename,filesize,filetype) ".
"VALUES ('$form_description','$data','$form_data_name',".
"'$form_data_size','$form_data_type')",
$conn);

$id = mysql_insert_id();
print "<p>This file has the following Database ID: <b>$id</b>";

mysql_close();

} else {
?>

<form method="post" action="<?php echo $PHP_SELF; ?>" enctype="multipart/form-data">
File Description:<br>
<input type="text" name="form_description" size="40">
<input type="hidden" name="MAX_FILE_SIZE" value="1000000">
<br>File to upload/store in database:<br>
<input type="file" name="form_data" size="40">
<p><input type="submit" name="submit" value="submit">
</form>

<?php

}

?>

</body>
</html>


Also, help me in retrieving the image from the database and showing it on a page.

do u think thiis will work now?

posted date: 2008-12-11 08:16:00


Re: image upload using php#2
I had made out the solution of this problem. click to view my topic...

hope that hepls.

posted date: 2008-12-11 08:16:01


Re: image upload using php#3
please fix spelling and provide the rest of your script.

posted date: 2008-12-11 08:25:00


Re: image upload using php#4
See http://www.php.net/manual/en/features.file-upload.phpInstead of using $form_data as the filename of the uploaded file, try $_FILES['form_data']['tmp_name']You could also replace the rather clumsyfread(fopen($form_data, "r"), filesize($form_data))withfile_get_contents($_FILES['form_data']['tmp_name'])

posted date: 2008-12-11 08:27:00


Re: image upload using php#5
I wouldn't suggest storing your binary image file directly in the database. Instead, store it on disk and store the file pointer (file directory + file name) in the DB.

posted date: 2008-12-11 09:33:00


Re: image upload using php#6
How can i save image in database using php please help me.

posted date: 2008-12-11 19:03:00


Re: image upload using php#7
The problem with storing images on the filesystem comes down to database replication. You would also need filesystem replication which can sometimes be harder than database replication especially when some servers may be remote.None of your $form_ variables are set (unless theres code I cant see or you 'dangerously' have register globals on). Also you will want to addslashes (or mysql_real_escape_string) on any queries that accept REQUEST values, else your script is prone to SQL injection.You want to:$form_description = isset($_POST['form_description']) ? $_POST['form_description'] : false;The other variables are not even being posted. Do you know any HTML and PHP? this is easy to resolve but I am not writing this for you!What we need is some feedback what the script produces.. you can get the image back by doing:$result = mysql_query ("SELECT `bin_data` FROM `your_table` WHERE `id` = ".$id, $conn);Then do for example (replacing the content type with the relevant type determined from the files array):$result_data = mysql_fetch_array($result, MYSQL_ASSOC);header('Content-Type: image/jpg');echo $result_data['bin_data'];exit;You need to do a bit more work to that script, and that requires knowledge of HTML, PHP and MySQL.

posted date: 2008-12-12 04:28:00


select page: « 1 »
Copyright ©2008-2017 www.momige.com, all rights reserved.