Jump to content

Adding multiple images for a product


bullbreed

Recommended Posts

I had a look at W3C Schools (School at 36 years old) :o  and came up with this to upload an image to a folder in the directory

 

// Check for a front image.
if ((($_FILES["pfrontimage"]["type"] == "image/gif")
|| ($_FILES["pfrontimage"]["type"] == "image/jpeg")
|| ($_FILES["pfrontimage"]["type"] == "image/pjpeg"))
&& ($_FILES["pfrontimage"]["size"] < 20000))
  {
  if ($_FILES["pfrontimage"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["pfrontimage"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["pfrontimage"]["name"] . "<br />";
    echo "Type: " . $_FILES["pfrontimage"]["type"] . "<br />";
    echo "Size: " . ($_FILES["pfrontimage"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["pfrontimage"]["tmp_name"] . "<br />";

    if (file_exists("uploads/" . $_FILES["pfrontimage"]["name"]))
      {
      echo $_FILES["pfrontimage"]["name"] . " This image already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["pfrontimage"]["tmp_name"],
      "uploads/" . $_FILES["pfrontimage"]["name"]);
      echo "Stored in: " . "uploads/" . $_FILES["pfrontimage"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }

 

But if I had say 5 images to upload would I duplicate this code 5 times on my page or could I use something like;

if ((($_FILES["image1"]["type"] || $_FILES["pimage2"]["type"] || $_FILES["image3"]["type"] || $_FILES["image4"]["type"] || $_FILES["image5"]["type"] == "image/gif" || "image/jpeg" || "image/pjpeg") && ($_FILES["pfrontimage"]["size"] < 20000))

 

Would it be any better code and time wise to duplicate it 5 times ?

Or would it be better to store them as an array or something.

 

Also on another note; (nothing to do with the images above) when I come to edit a product and I echo out the info in the database like this

<input name="prod_name" type="text" id="prod_name" size="25" value="<?php echo $row["prod_name"]; ?>"/>

 

Can I do this echo statement with checkboxes in the form. This would mean if I used a checkbox to add some information on the addproduct.php page, when I come to edit it in editproduct.php the checkboxes will already be checked. If I uncheck a checkbox and click submit it will amend the database. Bear in mind though that the checkboxes I use store the info as an array and I serialize the info in the database.

 

 

Link to comment
https://forums.phpfreaks.com/topic/192506-adding-multiple-images-for-a-product/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.