Click here to Skip to main content
15,745,506 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
How can I make an upload with PHP for four image files and also do:
Change the names of all the files to PHP defined names

Only allow upload of .jpg and .png formats

Each time a form is submitted it should save the files to a different folder

Print out the root of each file with the format in a separate tag

Zip all the files that were uploaded and change the name of the zip file to "images:" and place the download link inside the tag

What I have tried:

This is the code that I made

 $Message_sent = false;
if(isset($_POST['email']) && $_POST['email'] != ' '){
    if( filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) ){

$userName = $_POST['inputNmae'];
$userEmail = $_POST['inputEmail'];
$message = $_POST['inputMessage'];
$fileOne = $_POST['inputFileOne'];
$fileTwo = $_POST['inputFileTwo'];
$fileThree = $_POST['inputFileThree'];
$fileFour = $_POST['inputFileFour'];
$to = "";
$body = "";

$body .=  "From: \r\n".$userName. "\r\n\r\n";
$body .= "Email: \r\n".$userEmail. "\r\n\r\n";
$body .= "Message: \r\n".$message. "\r\n\r\n";
$body .= "File 1: \r\n".$fileOne. "\r\n\r\n";
$body .= "File 2: \r\n".$fileTwo. "\r\n\r\n";
$body .= "File 3: \r\n".$fileThree. "\r\n\r\n";
$body .= "File 4: \r\n".$fileFour. "\r\n\r\n";


$Message_sent = true;



<!DOCTYPE html>
<html lang="en">

  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">


<form action="mail.php" method="POST">

<label for="name">Name</label>
<input type="text" name="inputNmae" id="name">

<label for="email">Email</label>
<input type="email" name="inputEmail" id="email">

<label for="fileOne">Upload the summer photo</label>
<input type="file" name="inputFileOne" id="fileOne">
<p>your can only upload a file in the format of .jpg or .png</p>

<label for="fileTwo">Upload the fall photo</label>
<input type="file" name="inputFileTwo" id="fileTwo">
<p>your can only upload a file in the format of .jpg or .png</p>

<label for="fileThree">Upload the winter photo</label>
<input type="file" name="inputFileThree" id="fileThree">
<p>your can only upload a file in the format of .jpg or .png</p>

<label for="fileFour">Upload the spring photo</label>
<input type="file" name="inputFileFour" id="fileFour">
<p>your can only upload a file in the format of .jpg or .png</p>

<label for="message">Message</label>
<textarea name="inputMessage" id="message" cols="30" rows="10"></textarea>

  <p>Your files have been uploaded to  <br>
    The first picture <span id="theFirstPictureRoot"></span>
    The second picture <span id="theSecondPictureRoot"></span>
    The third picture <span id="theThirdPictureRoot"></span>
    The fourth  picture <span id="theFourth PictureRoot"></span>
  <a href="" id="downloadZipFile">Download zip file</a>

Member 15627495 13-Dec-22 12:51pm    
you divide the needs in a good way.

this part of php :
$userName = $_POST['inputName'];

could be :

$body .=  "From: \r\n".$_POST['inputName']."\r\n\r\n";

because $_POST is a var, an Array with all values in.
try it :
foreach($_POST as $item){
 echo $item;

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900