I want to have multiple image upload forms with only using one input.
The upload.php:
<?php
include("../include/session.php");
session_start();
$allowedExts = array("jpeg", "jpg", "png", "gif");
$extension = end(explode(".", $_FILES["upload"]["name"]));
if(isset($_FILES['upload']['tmp_name']))
{
for($i=0; $i < count($_FILES['upload']['tmp_name']);$i++)
{
if (($_FILES["upload"]["name"] < 90000000000000000)
&& in_array($extension, $allowedExts)) {
if ($_FILES["upload"]["error"] > 0)
{
header('location: '.$error); die;
}
else
{
if (file_exists("../icons/".$_SESSION["username"] ."/" . $_FILES["upload"]["name"]))
{
echo "error";
}
else
{
if(!is_dir("../icons/". $_SESSION["username"] ."/")) {
mkdir("../icons/". $_SESSION["username"] ."/");
}
$temp = explode(".",$_FILES["upload"]["name"]);
$file = rand(1,999999999999) . '.' .end($temp);
move_uploaded_file($_FILES["upload"]["tmp_name"], "../icons/". $_SESSION["username"] ."/". $file);
}
}
}
} else {
echo "yep error";
}
}
}
?>
If I take out the lines:
if(isset($_FILES['upload']['tmp_name']))
{
for($i=0; $i < count($_FILES['upload']['tmp_name']);$i++)
{
This works but only allows me to upload once. Can someone please guide me on making this work?