Jump to content


Photo

Question on posting values from a form


  • Please log in to reply
6 replies to this topic

#1 genista

genista
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 02 October 2006 - 01:36 PM

Hi all,

I have been given a script to look at that takes up to three images and uploads them to a directory. I now have to take the values of the images and post them to a database. The issue is that the form has a processing script that has been written around the name of each upload field being called: file[].

So I have three fields called file[] that user can add an image to and upload. The question is do I have to change the name to something like file1, then file2, file3 etc or is there some way I can take each value and post them into three fields in the database without changing this and therefore re-writing the processing script?

G

#2 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 02 October 2006 - 01:44 PM

read this - the second example is about multiple file uploads...

http://uk.php.net/features.file-upload
follow me on twitter @PHPsycho

#3 genista

genista
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 02 October 2006 - 01:56 PM

That second example is very much like what I have, the issue is that it has put each of the files[] into an array which is great, but it doesnt help me pull the three values out and into the database. Here is (hopefully) a better example:

<form action="" method="post" enctype="multipart/form-data">
<p>Pictures:
<input type="file" name="pictures[]" />
<input type="file" name="pictures[]" />
<input type="file" name="pictures[]" />
<input type="submit" value="Send" />
</p>
</form> 
<?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, "data/$name");
   }
}
?>  

I then have three fields in the database: file1, file2, file3, I want the contents of each of the html fields to be put into one of these database fields. The only way i can see now is to rename each html field file1, file2, etc but as I mentioned this would then involve rewriting the processing form.

I need it posted to the database so that on a different part of the site another user can look at the photos uploaded by someone else.




G

#4 ToonMariner

ToonMariner
  • Members
  • PipPipPip
  • Advanced Member
  • 3,342 posts
  • LocationNewcastle upon Tyne, UK

Posted 02 October 2006 - 02:11 PM

this all lies in your table structure.

there are lots or ways around this so unless you can show any table structure and how you want it used then can't really give u a specific answer.

I personally have a table just for images - upload all the image info into that table (path, atl text etc. etc.) then I simply store a comma separated string in a filed called 'images' for any record that needs to see them - then grab all those images using `image_id` IN (3,56,23) - (just an example string of image id's)
follow me on twitter @PHPsycho

#5 genista

genista
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 02 October 2006 - 02:44 PM

Ok, I have a table called supplier which will have the usual things about their details, and I have three fields called file1, file2, file3. I dont want to store them in a seperate table. I want a supplier to upload three images that a customer can view. Therefore I need the three files to populate the database and then I will call these locations on the user's page when they look at the supplier.


If there is an easier way to do this puleease let me know!


Thanks,

G

#6 redarrow

redarrow
  • Members
  • PipPipPip
  • Advanced Member
  • 7,308 posts
  • Locationlondon

Posted 02 October 2006 - 02:54 PM

what you do is add a colum called customer_images in customer_images you add the customer_id and date_sent and time_sent and image1,image2 image3.

you create a form that uses a array like above the user inserts three images the images goto image1 image2 image3 with the users_id date_sent and time_sent then display those images on the page needed.

in this situation i wouldnt let users post images i would create defualt images to the selling product then display those images where they need to be.

The truth of the matter is that when you start to let users add there images you intise hackers to upload there scripts to see what in your hardrive.


if you add images to a folder them neme the image to the product then add the name of the image to the database then show that image where it needs to be.

in doing somethink like this you would let the user select what item they are selling then update the datasae on the item they seleted with the pic name this way is much better ha?


if you contue and like the idear of letting users upload images then i sugest that you diffently with a toth pic do all the valadation as possable like the size of image the type of image and so on.

good luck.
Wish i new all about php DAM i will have to learn
((EMAIL CODE THAT WORKS))
http://simpleforum.ath.cx/mail2.inc
((PAYPAL INTEGRATION THAT WORKS))
http://simpleforum.a...aypal1_info.inc

#7 genista

genista
  • Members
  • PipPipPip
  • Advanced Member
  • 149 posts

Posted 02 October 2006 - 03:15 PM

The issue I have is that the products for sale are custom, plus I am thinking of creating a directory on my site for each supplier use mkdir and then posting their images to their own directory.

I intend on running a lot of transactions, so would it be better if the supplier uploads the photos, but instead of uploading to a directory they get emailed to myself so I can check them and then upload them from a private script that neither the user or supplier interacts with?

Anyone's thoughts?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users