Check multiple upload file

Can anyone help me how to create a link if there is a multiple upload file.
Example.

if i upload single file
the form will display single link for that upload data.

if there is a multiple upload file example. 3 file has been upload.
the form will display a 3 different link file to download.

thanks…

You may need to play with this because its been over a year since I used it but feel free to use this, modify it, mangle it etc…

I doubt its exactly what you want but you should be able to salvage usable code from it to get you on your way.


<?
session_start();
?>

<HTML>
<HEAD>
<TITLE>Form submission test.</TITLE>
<script type="text/javascript">
function addEvent()
{
var ni = document.getElementById('myDiv');
var numi = document.getElementById('FileCount');
var num = (document.getElementById("FileCount").value -1)+ 2;
numi.value = num;
var divIdName = "my"+num+"Div";
var newdiv = document.createElement('div');
newdiv.setAttribute("id",divIdName);
newdiv.innerHTML = "File: <input type='file' id='files[]' name='files[]'> <a href=\\"javascript:;\\" onclick=\\"removeEvent(\\'"+divIdName+"\\')\\">Remove</a>";
ni.appendChild(newdiv);
}

function removeEvent(divNum)
{
var d = document.getElementById('myDiv');
var olddiv = document.getElementById(divNum);
d.removeChild(olddiv);
var numi = document.getElementById('FileCount');
numi.value = numi.value - 1;
}
</script>
</HEAD>

<?
switch($_GET['mode'])
   {
   case "clear":
      $_SESSION['HTTP'] = NULL;
      Print "<A HREF=\\"$_SERVER[PHP_SELF]\\">Return</A>";
      exit();
      break;
   case "test":
      $_HTTP = $_SESSION['HTTP'];
      Print "Saved data was: <BR>";
      Print "<PRE>";
      Print var_dump($_HTTP);
      Print "</PRE>"; 
      
      Print "<A HREF=\\"$_SERVER[PHP_SELF]\\">Return</A><BR>";
      Print "<A HREF=\\"$_SERVER[PHP_SELF]?mode=clear\\">Clear Session.</A>";
      exit();
   default:
   ?>


   <CENTER>
      <FORM METHOD="post" enctype="multipart/form-data" ACTION="<? Print $_SERVER['PHP_SELF']; ?>">
      Module: <INPUT TYPE="text" NAME="module"><BR>
      Mode: <INPUT TYPE="text" NAME="mode"><BR>
      Command: <INPUT TYPE="text" NAME="command"><BR>
      <input type="hidden" value="0" id="FileCount" name='FileCount'>
   	<div id="myDiv"><script type="text/javascript">addEvent();</script></div>
   	<p><a href="javascript:addEvent();">Add field..</a></p>
      <INPUT TYPE="submit" NAME="submit" VALUE="Submit">
      <INPUT TYPE="submit" NAME="submit" VALUE="Save">
      </FORM>
   </CENTER>

   <?
   If ($_SESSION['HTTP'] != NULL)
      {
      $_HTTP = $_SESSION['HTTP'];
      }
   If (isset($_FILES['files']))
      {
      $_HTTP = NULL;
      }
      
   If ($_HTTP == NULL)
      {
      $_HTTP = $_GET + $_POST + $_FILES;
      }
   ?>

   Submitted Data was:<BR>

   <?
   $Count = count($_HTTP['files']['name']);

   Print "Files: $Count<BR>";
   
   $CurrDir = getcwd();
   print "$CurrDir<br>";
   for ($i = 0; $i < $Count; $i++)
      {
      $Temp = $_HTTP['files']['tmp_name'][$i];
      $Perm = $_HTTP['files']['name'][$i];
      
      If ((file_exists($Temp)) AND ($Temp != ''))
         {      
      	if(move_uploaded_file($Temp, $CurrDir ."\\$Perm"))
            {
            Print "<BR>Temp: $Temp<BR>";
            Print "Perm: $CurrDir" ."\\$Perm<BR>";
            Print "<A HREF=\\"$Perm\\">Download</A><BR>";
            }
           else
            {
               echo "File move failed (Temporary: $Temp).<BR>\
"; 
            }
         }
      else
         {
         If ((file_exists($Perm)) AND ($Perm != ''))
            {
            Print "<BR>Temp: $Temp<BR>";
            Print "Perm: $Perm<BR>";
            Print "<A HREF=\\"$Perm\\">Download</A><BR>";
            }
         else
            {
            If ($Temp != '')
               {
               echo "File move failed (Permanent: $Perm).<BR>\
";
               }
            }
         }
      }   
   ?>
   <BR>
   Saving data to session<BR>

   <?
   $_SESSION['HTTP'] = $_HTTP;
   break;
   }
?>

<A HREF="<? Print "$_SERVER[PHP_SELF]?mode=test"; ?>">Click here.</A><BR>
<A HREF="<? Print "$_SERVER[PHP_SELF]?mode=clear"; ?>">Clear Session.</A>
</HTML>

<?
Print "<PRE>";
Print var_dump($_HTTP);
Print "</PRE>"; 
?>

Thanks man…i really appreciate it.
i will just post if there is a problem…thanks again.

Hi,

where can i change the path to save the file.thanks


          if(move_uploaded_file($Temp, $CurrDir ."\\$Perm"))
            {
            Print "<BR>Temp: $Temp<BR>";
            Print "Perm: $CurrDir" ."\\$Perm<BR>";
            Print "<A HREF=\\"$Perm\\">Download</A><BR>";