/    Sign up×
Community /Pin to ProfileBookmark

display the user uploaded file types

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

[code=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=”&#1578;&#1581;&#1600;&#1600;&#1605;&#1610;&#1604;”>
</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&nbsp;”. $filen[$a] . “&nbsp;file<br>”;
}
}

?>

</div></td>
</tr>

?>
[/code]

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

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@bokehMar 18.2007 — The only way to conclusively do this is examine the contents of the file.
Copy linkTweet thisAlerts:
@roshanjameerauthorMar 18.2007 — hi,

here is my code.

for($a=0;$a<$uploadNeed;$a++) {

if (($ext==gif) or ($ext==jpg) or ($ext==psd) or ($ext==png) or ($ext==bmp))

{

echo "<img src='".$filen[$a]."'>";

}

else if(($ext==zip) or ($ext==swf) or ($ext==txt) or ($ext==mp3) or ($ext==avi) or ($ext==wmv) or ($ext==mpg) or ($ext==pdf) or ($ext==mpeg) or ($ext==rar) or ($ext==ram) or ($ext==rm) or ($ext==wav) or ($ext==doc) or ($ext==gz))

{

echo "you have uploaded the&nbsp;". $ext . "&nbsp;file<br>";

}}

here if i upload 2 or 3 images it is displaying all images.but if i upload one txt and one zip file,it is displaying that you have uploaded the zip file(it is taking the last uploaded file extension and printing the 2 times same message).if an image is uploaded,display image.if any other file is uploaded

just display all the uploaded file extensions.

thanks

mrjameer
×

Success!

Help @roshanjameer spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.2,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...