I have an upload script where I have 25 different file inputs.
They are all named upload[].
To access them on my processing page I have tried using things like
$_FILES['upload']['tmp_name'][$k]
and
$_FILES['upload'][$k]['tmp_name']
where k is a counter starting at 0 and going to 24 and corresponds to each index of the array.
Here is my actual script. It seems to be telling me that I cannot divide by zero down towards the bottom near $width45, and I'm figuring it is telling me that because it is looking for something that does not exist, which means the files are not uploading correctly. Any help on how to access each file from the $_FILES array let me know.
Thanks
if(isset($_POST['uploadForm']))
{
$upload = $_POST['upload'];
$title = $_POST['title'];
$album = $_POST['album'];
$k = 0;
$errors = 0;
while($k < 25)
{
$originalName = $_FILES['upload'][$k]['name'];
list($width, $length) = getimagesize($_FILES['upload'][$k]['tmp_name']);
if ($width > 3000 || $length > 3000)
{
$errors = 1;
$error .= "* Your image ".$originalName." has dimensions that are too large. (Images must be less than 3000 x 3000) *";
}
$getimagesize = getimagesize($_FILES['upload'][$k]['tmp_name']);
$fileType = $getimagesize['mime'];
if ($getimagesize != true)
{
$errors = 1;
$error .= "* Your image ".$originalName." is not a supported image type. (Images must be either .jpg, .jpeg, .gif or .png) *";
}
$target = 'photos/';
$target = $target ."/". basename($_SESSION['username'].'_'.$_FILES['upload']['name'][$k]) ;
$target = str_replace( " ", "_", $target );
$target = str_replace( "%",'p', $target);
$target = str_replace( "'",'a', $target);
if ( ($fileType == "image/jpeg") || ($fileType == "image/jpg") || ($fileType == "image/gif") || ($fileType == "image/png") || ($fileType == "image/pjpeg"))
{
if ($_FILES['upload'][$k]['size'] < 3000000)
{
if (is_uploaded_file($_FILES['upload'][$k]['tmp_name']))
{
if(move_uploaded_file($_FILES['upload'][$k]['tmp_name'], $target))
{
$name = $_SESSION['username'].'_'.$_FILES['upload'][$k]['name'];
$imageSize = $_FILES['upload'][$k]['size'];
$type = $fileType;
$title = $_POST['title'][$k];
$album = $_POST['album'][$k];
}
else
{
$errors = 1;
$error .= "* Image titled ".$originalName." could not be uploaded. *";
}
}
else
{
$errors = 1;
$error .= "* Image titled ".$originalName." could not be uploaded. *";
}
}
else
{
$errors = 1;
$error .= "* Image titled ".$originalName." was too big of an image to upload. *";
}
}
else
{
$errors = 1;
$error .= "* Your image ".$originalName." is not a supported image type. (Images must be either .jpg, .jpeg, .gif or .png) *";
}
if($errors == 0)
{
print $_POST['upload'][$k]['name'];
print $_POST['album'][$k];
print $_POST['title'][$k];
}
//Name you want to save your file as
$save = 'images/th_'.$name;
$thumb = "th_".$name;
$file = 'images/'.$name;
$imageType = $type;
list($width45, $height45) = getimagesize($file);
if ($width45 > $height45)
{
$width2 = 160/ $width45;
$height2 = $height45 * $width2;
$modwidth = 160;
$modheight = $height2;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
}
else
{
$width2 = 160/ $width45;
$height2 = $height45 * $width2;
$modwidth = 160;
$modheight = $height2;
$tn = imagecreatetruecolor($modwidth, $modheight) ;
}
// Here we are saving the .jpg, you can make this gif or png if you want
//the file name is set above, and the quality is set to 100%
if (($imageType == "image/jpeg") || ($imageType == "image/jpg") || ($imageType == "image/pjpeg"))
{
$image = imagecreatefromjpeg($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
imagejpeg($tn, $save, 100);
}
if (($imageType == "image/gif"))
{
$image = imagecreatefromgif($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
imagejpeg($tn, $save, 100);
}
if ($imageType == "image/png")
{
$image = imagecreatefrompng($file) ;
imagecopyresampled($tn, $image, 0, 0, 0, 0, $modwidth, $modheight, $width, $height) ;
imagepng($tn, $save, 100);}
$k = $k + 1;
}
}