Computing.Net > Forums > Web Development > how upload image into mysql with php

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

how upload image into mysql with php

Reply to Message Icon

Name: murali s
Date: April 23, 2009 at 16:05:23 Pacific
OS: Windows XP
Subcategory: PHP
Comment:

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....

by

murali s



Sponsored Link
Ads by Google

Response Number 1
Name: shutat
Date: April 24, 2009 at 12:23:12 Pacific
Reply:

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" />
</form>

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

<?php
// 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:';
print_r($_FILES);

?> 

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


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Web Development Forum Home


Sponsored links

Ads by Google


Results for: how upload image into mysql with php

cannot connect to mysql with php www.computing.net/answers/webdevel/cannot-connect-to-mysql-with-php/2968.html

How to add an Image to a database www.computing.net/answers/webdevel/how-to-add-an-image-to-a-database/2147.html

Fit image into an html with PHP www.computing.net/answers/webdevel/fit-image-into-an-html-with-php/2223.html