sayr Posted February 13, 2007 Share Posted February 13, 2007 Hello! I have a problem here which i really don't get... I have a database and a form which uploads typed data and image if wanted. What I want is a working script that uploads chosen picture to server and makes the link of the picture to mysql database. It's like an webshop which has products listed and evey product has it's picture there... I have two files; upload.php and uploaded.php Here is the image upload part from upload.php; <form method="post" action="uploaded.php" enctype="multipart/form-data"> ...some code here... <strong>2. Image upload</strong><br><br> <input type="file" name="image[]" alt="image" size=50 maxlength=100><br><br> ...some code here too... <input type="submit" name="action" value="Save"> Ok so next one is uploaded.php; ...some code here... foreach ($_FILES["image"]["error"] as $key => $error) { if ($error == UPLOAD_ERR_OK) { $tmp_name = $_FILES["image"]["tmp_name"][$key]; $name = $_FILES["image"]["name"][$key]; move_uploaded_file($tmp_name, "images/$name"); } } $image=$name; ...some code here... I didn't paste the whole code, because there is a huge line of it. So that code uploads the image to /images file, but it doesn't add the image name(link) to database. The database field "image" is just empty. Could you help me with this please! Thanks! Quote Link to comment Share on other sites More sharing options...
benjaminbeazy Posted February 13, 2007 Share Posted February 13, 2007 are you storing the image in the database or just the link to it, have you generated the link itself and just not gotten in the db or what? Quote Link to comment Share on other sites More sharing options...
sayr Posted February 13, 2007 Author Share Posted February 13, 2007 Yes im trying to store the link to database, not the image. The image I want to be uploaded in server (which it does already)... I am quite new with php so im not sure is that code making a link to db? Earlier it actually did wrote the name of the uploaded picture to database, but then it didn't upload the image itself to server... And now it's the opposite Quote Link to comment Share on other sites More sharing options...
Parabolundertow Posted February 14, 2007 Share Posted February 14, 2007 I had the same issue to start with, Then I saw that I needed to look at what is getting sent in the insert script. If I remember correctly... I set a variable $address = 'http://www.yoursite.com.au/images/" Then I had my File Uploader for the image to go to folder destination = images/$image After that I made $image_name = $address . $image under the File Uploader Sending the $image_name to the database. So.... The database receives (http://www.yoursite.com.au/images/image_name.jpg) Folder receives (image_name.jpg) Is this any help ? Cheers Quote Link to comment Share on other sites More sharing options...
redarrow Posted February 14, 2007 Share Posted February 14, 2007 you post all the code and indent the code ok. Quote Link to comment Share on other sites More sharing options...
s0c0 Posted February 14, 2007 Share Posted February 14, 2007 In your mysql insert statement you'll want to take the image name $_POST['image'] and do something like this: $imageinsert = "INSERT INTO imagetable (image, value1, value2) VALUES ('$_POST[image]', 'value1', 'value2')"; mysql_query($yourconnectionstring, $imageinsert); I am not on a lamp box right now so I can't verify the above code, but something very similiar to that should work. I am developing an application with this feature in it and that code works. If you want a better example I can post my code when I get home. Quote Link to comment 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.