mrjameer Posted March 17, 2007 Share Posted March 17, 2007 hi, in my image upload site till now only one text box for one image/any file uploads.but i modified it so that the user if he enter 2 it will dynamically create 2 textboxes so that he can upload 2 files.if he enter 9 he can upload 9 files(maximum limit 9). when a user uploads the zip file and jpg file and bitmap or any other file,how can i display the file types which is uploaded by a user. this works but when i upload all images it will displays all images,if i upload all types of files except images it will displays last uploaded file repeatedly.problem is when i upload 1 image and 1 text file,it is taking the last file upload and displays that extension only upload_6.php <?php if( $_POST['submit']) { for($a=0;$a<$uploadNeed;$a++) { $ok_filetypes = explode("|",$att_filetypes); if (!$_FILES['uploadFile'. $a]['name'] && $_FILES['uploadFile'. $a]['name'] > $att_max_size*1024) { errform('<CENTER>Sorry, but the attached file is too large. Please reduce the size of it's contents.</CENTER><BR><BR>'); // #err $step = 1; } $filename = (!$_FILES['uploadFile'. $a]['name'] ? substr( basename($_FILES['uploadFile'. $a]['name']), -30 ) : ''); $x = strtolower( substr($_FILES['uploadFile'. $a]['name'], -3)); if($filename && !in_array($x, $ok_filetypes) ) { errform('<CENTER>Sorry, the filetype you have tried to upload is not allowed.</CENTER><BR><BR>'); $step = 1; } if(!$posterr) { if(!isset($_GET["ipaddress"]) || ($_GET["ipaddress"] == "")) { $ipaddress = $_SERVER['REMOTE_ADDR']; $local = 1; } else { $ipaddress = $_GET["ipaddress"]; $local = 0; } $uniq = substr( md5(uniqid (rand())), 0, 10 ); $ext = strtolower( substr($_FILES['uploadFile'. $a]['name'], -3)); move_uploaded_file($_FILES['uploadFile'. $a]['tmp_name'], $att_path."/".$uniq.".".$ext ); $strQuery = "INSERT INTO images SET "; $strQuery .= "filename='".$uniq.".".$ext."',"; $strQuery .= "ipaddress='{$ipaddress}',"; $strQuery .= "date='".time()."',"; $strQuery .= "pkey='{$uniq}',"; if($myuid) { $strQuery .= "user='{$myuid}',"; } $strQuery .= "status='1'"; $result = mysql_query($strQuery) or die( mysql_error() ); $aid = mysql_insert_id(); if($aid) { $filen[$a] = $siteurl."/".str_replace('./', '', $att_path)."/".$uniq.".".$ext; $filen[$a] = str_replace('http://','%%',$filen[$a]); $filen[$a] = str_replace('//','/',$filen[$a]); $filen[$a] = str_replace('%%','http://',$filen[$a]); $step = 2; } else { $step = 1; } } } } else{ $step = 1; } if($step == 1) { ?> <html> <head> </head> <body> <table width="85%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td> <div align=center> <form ENCTYPE="multipart/form-data" method="post" name="form1"> <p> <? // start of dynamic form $uploadNeed = $_POST['uploadNeed']; for($y=0;$y<$uploadNeed;$y++){ ?> <input name="uploadFile<? echo $y;?>" type="file" id="uploadFile<? echo $y;?>"> </p> <? // end of for loop } ?> <p><input name="uploadNeed" type="hidden" value="<? echo $uploadNeed;?>"> <input type="submit" name="submit" value="تحــميل"> </form> </div> </td> </tr> </table></body> <? } else{ ?> <div align="center"><b>aa</b><br> <br> </div> <table width="85%" border="0" align="center" cellpadding="0" cellspacing="0"> <tr> <td><div align="center"> <?php for($a=0;$a<$uploadNeed;$a++) { $size = getimagesize("$filen[$a]"); $height = $size[1]; $width = $size[0]; if ($height > 250) { $height = 100; $percent = ($size[1] / $height); $width = ($size[0] / $percent); } else if ($width > 250) { $width = 200; $percent = ($size[0] / $width); $height = ($size[1] / $percent); } if($filen[$a] > 5) { echo "</BR>"; } if (($ext==gif) or ($ext==jpg) or ($ext==psd) or ($ext==png) or ($ext==bmp)) { echo "<img src='".$filen[$a]."' border='0' height='$height' width='$width'>"; } else { echo "you have uploaded the ". $filen[$a] . " file<br>"; } } ?> </div></td> </tr> ?> upload.php <form ENCTYPE="multipart/form-data" method="post" name="form1" action="upload_6.php"> <p>Enter the amount of boxes you will need below. Max = 9.</p> <p><input name="uploadNeed" type="text" id="uploadNeed" maxlength="1" size="30"> </p> <p><input type="submit" name="Submit" value="Submit"></p> </form> thanks mrjameer Quote Link to comment https://forums.phpfreaks.com/topic/43155-display-the-user-uploaded-file-types/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.