Jump to content

Question on posting values from a form


genista

Recommended Posts

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
Link to comment
Share on other sites

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:

[code=php:0]
<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");
  }
}
?> 
[/code]

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
Link to comment
Share on other sites

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)
Link to comment
Share on other sites

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
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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?
Link to comment
Share on other sites

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.