Hi all,
Im working on my first real php site and have hit a spot of bother. Im trying to have an input form that uploads UP TO 5 images to a file server, randomises the names and stores the path in a mysql table.
I can get it to work with 1 image no worries.
I can get it to work with 2 images but once i put extra code to handle the second image if the user only inputs 1 image it throws an error about not having a second image.
I would really appreciate some help in allowing up to 5 images but if they select 1 or 2 then so be it.
This is what i have at the moment.
if(isset($POST['submit']))
{
$fileName = $FILES['userfile']['name'];
$tmpName = $FILES['userfile']['tmp_name'];
$fileSize = $FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$ext = substr(strrchr($fileName, "."), 1);
$randName = md5(rand() * time());
$filePath = $uploadDir . $randName . '.' . $ext;
$result = move_uploaded_file($tmpName, $filePath);
if (!$result) {
echo "Error uploading file 1";
exit;
}
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}
$fileName2 = $_FILES['userfile2']['name'];
$tmpName2 = $_FILES['userfile2']['tmp_name'];
$fileSize2 = $_FILES['userfile2']['size'];
$fileType2 = $_FILES['userfile2']['type'];
$ext2 = substr(strrchr($fileName2, "."), 1);
$randName2 = md5(rand() * time());
$filePath2 = $uploadDir . $randName2 . '.' . $ext2;
$result2 = move_uploaded_file($tmpName2, $filePath2);
if (!$result2) {
echo "Error uploading file 2";
exit;
}
if(!get_magic_quotes_gpc())
{
$fileName2 = addslashes($fileName2);
$filePath2 = addslashes($filePath2);
}