Page 1 of 1

Get Names of Uploaded Files And Information Into A Hidden

Posted: Sun Apr 30, 2006 6:38 pm
by billhobbs
I need to be able to get the results of the uploaded files. The Name & whether it was uploaded or not into a hidden so that I can post it on the next page and put it into an email. I've tried several things and none of them work. Here is the code that uploads and gives you the uploaded information.

Code: Select all

<?
$num_of_uploads=10;
$file_types_array=array("jpg", "JPG", "pdf", "PDF");
$max_file_size=1048576;
$upload_dir="";

function uploaderFILES($num_of_uploads=1, $file_types_array=array("jpg", "JPG", "pdf", "PDF"), $max_file_size=1048576, $upload_dir=""){
if(!is_numeric($max_file_size)){
$max_file_size = 1048576;
}
foreach($_FILES["file"]["error"] as $key => $value)
{
if($_FILES["file"]["name"][$key]!="")
{
if($value==UPLOAD_ERR_OK)
{
$origfilename = $_FILES["file"]["name"][$key];
$filename = explode(".", $_FILES["file"]["name"][$key]);
$filenameext = $filename[count($filename)-1];
unset($filename[count($filename)-1]);
$filename = implode(".", $filename);
$filename = substr($filename, 0, 15).".".$filenameext;
$file_ext_allow = FALSE;
for($x=0;$x<count($file_types_array);$x++){
if($filenameext==$file_types_array[$x])
{
$file_ext_allow = TRUE;
}
} // for
if($file_ext_allow){
if($_FILES["file"]["size"][$key]<$max_file_size){
if(move_uploaded_file($_FILES["file"]["tmp_name"][$key], $upload_dir.$filename)){
echo("File Uploaded Successfully. - <a href='".$upload_dir.$filename."' target='_blank'>".$filename."</a><br />");
} 
else { echo('<font color="#FF0000">'.$origfilename."</font> Was Not Successfully Uploaded<br />");}
}
else { echo('<font color="#FF0000">'.$origfilename."</font> Was Too Big, Not Uploaded<br />"); }
} // if
else{ echo('<font color="#FF0000">'.$origfilename." </font>Had An Invalid File Extension<br />"); }
}
else{ echo('<font color="#FF0000">'.$origfilename." </font>Was Not Successfully Uploaded<br />"); } // else
}
}
} // funtion


?>
<form action='<?=$PHP_SELF;?>' method='post' enctype='multipart/form-data'>
You may upload up to 10 files. They must all be in either Jpg or Pdf formats. All other types of files will be rejected by the server. <br />
<input type='hidden' name='submitted' value='TRUE' id='<?=time();?>' >
<input type='hidden' name='MAX_FILE_SIZE' value='<?=$max_file_size;?>' >
<? for($x=0;$x<$num_of_uploads;$x++){
$form .= "<input type='file' name='file[]'><br />";
}
$form .= "<input type='submit' value='Upload'><br />
<font color='red'>*</font>Maximum file length (minus extension) is 15 characters. Anything over that will be cut to only 15 characters. Valid file type(s): ";
for($x=0;$x<count($file_types_array);$x++){
if($x<count($file_types_array)-1){
$form .= $file_types_array[$x].", ";
}else{
$form .= $file_types_array[$x].".";
}
}
echo($form);
?> 
</form>

Posted: Sun Apr 30, 2006 8:36 pm
by feyd
I would not under any circumstances recommend passing that information to the user so they can submit it back. What if I intercept the fields and alter them to maybe an htpasswd file or something else? Bad things, right. I'd store the data in session variables. I'd still verify the data once on the second page, but at least in a session variable it's a bit more secured and safe from the user, at least, fiddling with the information.

Posted: Sun Apr 30, 2006 8:51 pm
by billhobbs
How do I extract the uploaded file names so that they can be put into a session variable. The next page includes a questionaire form should that be a session variable also.