Page 1 of 1

uploading an image

Posted: Fri Mar 18, 2011 5:37 am
by superchrisc
Hey, i need help storing an image in my database via the URL(image location) at the moment my php code is storing the image in a folder on the directory called upload. here is the code:

Code: Select all

<?php 
// Where the file is going to be placed 
$target_path = "upload
/";

/* Add the original filename to our target path.  
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
$target_path = "upload/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}
?>
Click <a href="products.php">HERE</a> to go back to form


if someone could help me i'd be very grateful

Re: uploading an image

Posted: Fri Mar 18, 2011 8:12 am
by Bind
ok ... what is it exactly that you need help WITH ?

you have shown no database information - table or row structure or even the type of database you are using.

at a minimum, you will want a unique identifier and a filename. Other options could include a image title, description, owner name, etc.

you will need to create a database, a user for the database associated with the right permission to use the database, a table, then the row structure relating to the options mentioned above. Then you would need to construct code to access, write, and read from your db table, which depends on the database used.

There are many db tutorials out there. I would suggest you start with google and start reading.

Then construct your code and feel free to post it if you ahve any problems and e can help you with it.

Re: uploading an image

Posted: Tue Mar 22, 2011 10:54 am
by akuji36
Hello

I have been told that it's better to simply store the location of the image in mysql db

rather than use a 'blob type' column and insert image. However here's a link which shows

a db with an image upload:
http://www.anyexample.com/programming/p ... age%29.xml