how upload image into mysql with php

April 23, 2009 at 16:05:23
Specs: Windows XP
i want upload image into my page and store in database then how that image placed in my page. And important delete,edit,insert the image in db. please reply must....


murali s

See More: how upload image into mysql with php

Report •

April 24, 2009 at 12:23:12
In general, add a form that uploads data. Here's an example form the php help file.

<form enctype="multipart/form-data" action="some_url" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />

You'll need to know the absolute path to your document root because you'll need to move the file at some point.

// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used instead
// of $_FILES.

$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
    echo "File is valid, and was successfully uploaded.\n";
} else {
    echo "Possible file upload attack!\n";

echo 'Here is some more debugging info:';


Once the file is validated, you'll need to insert or update its path in your database. The general syntax is similar to below, but you'd need to use whatever your table values are.

$res = mysql_query("insert into tbl_name values(...);");

To retrieve, query the table again for the image path; Again it's just a basic example; you'd need to use whatever you have defined in your table.

$res = mysql_query("select img_path from tbl_name where imgID = '1'");

My work in progress. I hate JS. :P

Report •
Related Solutions

Ask Question