Jump to content

Images and Database with Form help. Anyone know about this?


Recommended Posts

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:\folder\desktop\theproduct.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.

I read it... I already knew that.

 

What I said was I'm Good with image and file uploads using PHP.

 

Just need help with this:

Only thing I don't get is how to put the image name into the database

AND

putting the images/files into the right folder

 

 

Here is some image upload directory help I need:

The code will WORK GOOD if I change

move_uploaded_file($tmp_name,

    "../../../images/component/uploads/$name");

-- TO --

move_uploaded_file($tmp_name,

    "uploads/$name");

 

BUT I dont want it in the folder...

 

>> Heres what I got >>

 

<?php  
foreach ($_FILES["pictures"]["error"] as $key => $error) { 
if ($error == UPLOAD_ERR_OK) {
    $tmp_name = $_FILES["pictures"]["tmp_name"][$key];
    $name = $_FILES["pictures"]["name"][$key];
    move_uploaded_file($tmp_name, 
    "../../../images/component/uploads/$name"); 
    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:\wamp\www\shoppingcart\admin\test\imagetesting\add_images_processing.php on line 87

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'c:/wamp/tmp\php12B.tmp' to '../../../images/component/uploads/me.jpg' in C:\wamp\www\shoppingcart\admin\test\imagetesting\add_images_processing.php on line 87

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.