uploading an image

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
superchrisc
Forum Newbie
Posts: 1
Joined: Fri Mar 18, 2011 5:29 am

uploading an image

Post 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
Bind
Forum Contributor
Posts: 102
Joined: Wed Feb 03, 2010 1:22 am

Re: uploading an image

Post 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.
User avatar
akuji36
Forum Contributor
Posts: 190
Joined: Tue Oct 14, 2008 9:53 am
Location: Hartford, Connecticut

Re: uploading an image

Post 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
Post Reply