Jump to content

Recommended Posts

Hi, I wonder if someone can help, I have a simple image upload form that works well, however I would like to be able to upload more than one image with the form, idealy four images. I knowe their are specific forms for doing this however we would really like to stick with our current form if possible. I've been playing around with it but just can't seem to find the right code to dublicate the image upload field. Any and all help much appreciated.

 

The form code is as follows

 

---

 

<form method="post" action="output.php" enctype="multipart/form-data">

                         <table width="370" border="0" align="center" cellpadding="0" cellspacing="0" bordercolor="#FFFFFF">

<table width="100%" border="0" cellspacing="0" cellpadding="5">

         <tr>

         <td width="38%"><div align="left">Your

           Name</font></div></td>

         <td width="62%"><div align="left">

           <input style="color: #333333; font-family: Arial; font-size: 12px; background-color: #F7F7F7;" name="Name" type="text" id="Name" size="40">

         </div></td>

       </tr>

       <tr>

         <td><div align="left">Your

           Email</font></div></td>

         <td><div align="left">

           <input style="color: #333333; font-family: Arial; font-size: 12px; background-color: #F7F7F7;" name="email" type="text" id="email2" size="40">

         </div></td>

       </tr>

<tr>

                             <td valign="top"><div align="left">Your Telephone</div></td>

                             <td>

                                 <div align="left">

                                   <input style="color: #333333; font-family: Arial; font-size: 12px; background-color: #F7F7F7;" name="ContactNumber" id="ContactNumber" size="40" maxlength="35" />

                                 </div></td>

               </tr>

                           <tr>

                             <td colspan="2" valign="top"><div align="left">Please Add any additional detail below. </div></td>

                           </tr>

                           

                           <tr>

                             <td colspan="2" valign="top">

                                 <div align="left">

                                   <textarea style="color: #333333; font-family: Arial; font-size: 12px; background-color: #F7F7F7;" name="Comments" cols="31" rows="5" id="Comments"></textarea>

                               </div></td>

                           </tr>

                           <tr>

                             <td colspan="2">Please upload an image below. <span class="style1"><br />

                             Please note that only gif, png, jpg and jpeg file formats are accepted.</span></td>

                           </tr>

               <tr>

         <td colspan="2"><div align="center">

             <input style="color: #333333; font-family: Arial; font-size: 12px; background-color: #F7F7F7;" name="upload" type="file" size="40">

 <br />

   <input style="color: #333333; font-family: Arial; font-size: 12px; background-color: #F7F7F7;" name="upload2" type="file" size="40">

           </div></td>

       </tr>

     </table>

 

And the php of the output file is:

 

<?php

 

@$Comments = addslashes($_POST['Comments']);

@$Name = addslashes($_POST['Name']);

@$email = addslashes($_POST['email']);

@$ContactNumber = addslashes($_POST['ContactNumber']);

@$upload_Name = $_FILES['upload']['name'];

@$upload_Size = $_FILES['upload']['size'];

@$upload_Temp = $_FILES['upload']['tmp_name'];

@$upload_Mime_Type = $_FILES['upload']['type'];

 

function RecursiveMkdir($path)

{

  if (!file_exists($path))

  {

     RecursiveMkdir(dirname($path));

     mkdir($path, 0777);

   }

 }

 

 

if (! ereg('[A-Za-z0-9_-]+\@[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+', $email))

{

die("<p align='left'><b><font face='Avenir Medium' size='2' color='#000000'>Please enter a valid email</font></b></p>");

}

 

if( $upload_Size == 0)

{

die("<p align='left'><b><font face='Avenir Medium' size='2' color='#000000'>ERROR<br>Your file was not uploaded<br>Please check the file size and format.</font></b></p>");

}

 

if( $upload_Size >80000000)

 

{

unlink($upload_Temp);

die("<p align='left'><b><font face='Avenir Medium' size='2' color='#999999'>ERROR<br>Your file was not uploaded<br>Please check the file size and format.</font></b></p>");

}

if( $upload_Mime_Type != "image/cgm" AND $upload_Mime_Type != "image/g3fax" AND $upload_Mime_Type != "image/gif" AND $upload_Mime_Type != "image/ief" AND $upload_Mime_Type != "image/pjpeg" AND $upload_Mime_Type != "image/jpeg" AND $upload_Mime_Type != "image/naplps" AND $upload_Mime_Type != "image/png" AND $upload_Mime_Type != "image/prs.btif" AND $upload_Mime_Type != "image/prs.pti" AND $upload_Mime_Type != "image/tiff" AND $upload_Mime_Type != "image/vnd.cns.inf2" AND $upload_Mime_Type != "image/vnd.dwg" AND $upload_Mime_Type != "image/vnd.dxf" AND $upload_Mime_Type != "image/vnd.fastbidsheet" AND $upload_Mime_Type != "image/vnd.fpx" AND $upload_Mime_Type != "image/vnd.fst" AND $upload_Mime_Type != "image/vnd.fujixerox.edmics-mmr" AND $upload_Mime_Type != "image/vnd.fujixerox.edmics-rlc" AND $upload_Mime_Type != "image/vnd.mix" AND $upload_Mime_Type != "image/vnd.net-fpx" AND $upload_Mime_Type != "image/vnd.svf" AND $upload_Mime_Type != "image/vnd.wap.wbmp" AND $upload_Mime_Type != "image/vnd.xiff" )

{

unlink($upload_Temp);

die("<p align='left'><b><font face='Avenir Medium' size='2' color='#999999'>ERROR<br>Your file was not uploaded<br>Please check the file size and format.</font></b></p>");

}

$uploadFile = "uploads/".$upload_Name ;

if (!is_dir(dirname($uploadFile)))

 {

   @RecursiveMkdir(dirname($uploadFile));

 }

else

 {

 @chmod(dirname($uploadFile), 0777);

 }

@move_uploaded_file( $upload_Temp , $uploadFile);

chmod($uploadFile, 0644);

 

 

$upload_URL = "http://sitename.co.uk/uploads/".$upload_Name ;

 

 

$pfw_header = "From: $email";

$pfw_subject = "form name";

 

 

$pfw_email_to = "contact@emailaddress.co.uk";

 

$pfw_message = "email: $email\n"

 

. "Name: $Name\n"

. "Tel Number: $ContactNumber\n"

. "Comments: $Comments\n"

. "upload: $upload_URL\n";

@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

 

echo("<p align='left'><b><font face='Avenir Medium' size='2' color='#000000'>Thank you for your email.<br>Your image and application were susessfully uploaded.</font></b></p>");

?>

 

---

 

Thank you.

Link to comment
https://forums.phpfreaks.com/topic/64670-solved-help-with-image-upload-form-php/
Share on other sites

Hi, Many thanks for the reply.

 

Yeah, I've been trying to do something along those lines but I don't know, can't get the right php to process the second image. Been trying all day.

 

It seems a relatively simple script, which is why I'd rather keep using it, however its beyond my knoledge of php.

 

 

Nobody?

 

I know I need to duplicate the

 

<input style="color: #333333; font-family: Arial; font-size: 12px; background-color: #F7F7F7;" name="upload" type="file" size="40">

 

area within the form, changing the name,

 

but then I just can't figure out the correct code to process it on the output .php, Anybody help?

 

Thank you.

Many thanks, I'll take a look at it...

 

'takes look'

 

...Yeah, that will upload multiple images however I'm loosing both the form email side of what I have, I probbly should have explained more that one of the reasons that I wanted to keep this form is the way it emails both a link to the file ive uploaded and several other form fields when submitted.

 

I could probbly figure out how to fit that within a standard form but then I know I wouldn't be able to script the php to include links to what was uploaded in that email.

Hi Chris,

 

I think you'll find this will do what you need and is again based on a simple single page script. [its the form on the second page that works]

 

http://www.vodahost.com/vodatalk/forms/7233-how-upload-file-using-form.html

 

All the best,

 

Chris.  ;D

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.