bri0987 Posted October 18, 2007 Share Posted October 18, 2007 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. Quote Link to comment https://forums.phpfreaks.com/topic/73883-images-and-database-with-form-help-anyone-know-about-this/ Share on other sites More sharing options...
Wes1890 Posted October 18, 2007 Share Posted October 18, 2007 By chance have you looked at the php manual? http://php.net/ And here is a good tutorial on doing this (the uploading part) http://www.tizag.com/phpT/fileupload.php Google is your friend.... Quote Link to comment https://forums.phpfreaks.com/topic/73883-images-and-database-with-form-help-anyone-know-about-this/#findComment-372817 Share on other sites More sharing options...
bri0987 Posted October 19, 2007 Author Share Posted October 19, 2007 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 Quote Link to comment https://forums.phpfreaks.com/topic/73883-images-and-database-with-form-help-anyone-know-about-this/#findComment-372990 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.