I have the following code to upload a file to a folder, depending on the file input upload the file is renamed e.g. the first input - the picture is renamed to picture01.jpg, the 5th input - the picture is renamed to picture to picture01.jpg, etc...
<form action="upload_file.php" enctype="multipart/form-data" method="POST">
<p><input name="image01" type="file"> </p>
<p><input name="image02" type="file"> </p>
<p><input name="image03" type="file"> </p>
<p><input name="image04" type="file"> </p>
<p><input name="image05" type="file"> </p>
<input type="submit" value="Upload File">
</form>
This is upload_file.php -
<?php
$pic_names = array (
'01' => 'picture01',
'02' => 'picture02',
'03' => 'picture03',
'04' => 'picture04',
'05' => 'picture05',
);
$folder = "temp_images/";
if(preg_match("/(jpg|jpeg|png|gif|mp3|mp4)/",$ext)) {
// Picture01
$image_path01 = $folder . $pic_names['01'] . '.jpg';
move_uploaded_file($_FILES['image01']['tmp_name'], $image_path01);
// Picture02
$image_path02 = $folder . $pic_names['02'] . '.jpg';
move_uploaded_file($_FILES['image02']['tmp_name'], $image_path02);
// Picture03
$image_path03 = $folder . $pic_names['03'] . '.jpg';
move_uploaded_file($_FILES['image03']['tmp_name'], $image_path03);
// Picture04
$image_path04 = $folder . $pic_names['04'] . '.jpg';
move_uploaded_file($_FILES['image04']['tmp_name'], $image_path04);
// Picture05
$image_path05 = $folder . $pic_names['05'] . '.jpg';
move_uploaded_file($_FILES['image05']['tmp_name'], $image_path05);
echo 'Uploaded successfully!';
} else { echo 'Uploaded successfully!';}
?>
I would like to check that before the file is uploaded it is checked that either one of the following extensions exist prior to uploading jpg, gif or png. If they have another extension then it is not uploaded and an error is given.
The only solution I managed to find is when the input name="image" type="file"> have the same name e.g. in this case name. How can I do it for my case with different names for the input?
I got the follwoing error: PHP Parse error: syntax error, unexpected T_ELSE
Though I am sure that it more than a parse error.
Any suggestion or help please?
UPDATE: I amended the code but its telling me that 'Wrong file type!' for any image format too.