[SOLVED] Image and Database with Form help. Anyone know??

Can This be done with PHP?

I have a form that inserts Product data into the database, as well as one form that edits (updates) Products in the database.
at this address for example: “http://Localhost/shoppingcart/admin/addproduct.php
Its working great. One of the fields in both forms is “Image”. The user types in the name of an image that has previously been uploaded to the hosting images directory via FTP. For example the user types: “TheProduct.jpg”

The whole FTP thing for the user is far to complicated so I want to make this easier.

  • What I’m looking for is a field that will no allow the user to type into it.
  • The user clicks onto a browse button next to the field.
  • The user browses his/her own harddrive and finds the image they want. Example: C:folderdesktoptheproduct.jpg
  • They select the image.
  • Complete the rest of the form.
  • Click submit.

The form will take the image selected and copy it to a folder onto the host machine:
for example: http://Localhost/shoppingcart/images/

The name of the image file is all that will be stored into the database. For example the image field it will only store “theproduct.jpg”

How can this be done in PHP.

Also second question:
I already know how to do this:
I already know know to make a file field in a form and upload an image to an upload folder directing in the same folder as the form folder. For example, what I mean is: If “uploadimage.php” is in the folder “http://localhost/imageuploadtesting/” … I know how to upload an image file to: “http://localhost/imageuploadtesting/test/uploads/” … but NOT outside of the “/test/” folder… I tried using things like $path = “…images/”; so that the file would upload to “/imageuploadtesting/images” … but it trys to upload to “http://localhost/imageuploadtesting/test/…images/” which is not there…
Anyways, thats my second question. I need help with the top one more.

  1. http://php.net/file-upload

  2. $path = “…/images/”

its good to rename the file. e.g. numberic to be the same as the PRIMARY KEY of a mysql table.

The code will WORK GOOD if I change
– TO –

BUT I dont want it in the folder…

Heres what I got >>

foreach ($_FILES["pictures"]["error"] as $key => $error) { 
if ($error == UPLOAD_ERR_OK) {
    $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
    $name = $_FILES["pictures"]["name"][$key];
    echo "DONE! <br />";
    echo $name . "<br />"; 
} else {
    echo "Error <br />";
    print_r ($_FILES);

This returns errors…

Warning: move_uploaded_file(…/…/…/images/component/uploads/me.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:wampwwwshoppingcartadmintestimagetestingadd_images_processing.php on line 87

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move ‘c:/wamp/tmpphp12B.tmp’ to ‘…/…/…/images/component/uploads/me.jpg’ in C:wampwwwshoppingcartadmintestimagetestingadd_images_processing.php on line 87

is the folder C:wampwwwshoppingcartimagescomponentuploads realy existing (PHP isn’t creating the folders automaticly)?

if yes i must be a problem with the include-path or the rights (but afaik that is returnd by the errormsg explicitly)

Sponsor our Newsletter | Privacy Policy | Terms of Service