hi,
i have the script that will upload 3 images in folder and also stores image path in mysql table.what happen if any body want to upload one image only or 2 images only.how can i handle it.
[code=php]
<?php
$siteurl = “http://localhost/ahmup”;
$adminemail = “[email protected]”;
$att_max_size = ‘50000000000000’;
$att_filetypes = “gif|jpg|png|zip|swf|txt|bmp”;
$dbServer = “localhost”;
$dbUser = “”;
$dbPass = “”;
$dbName = “bbb”;
@mysql_connect($dbServer, $dbUser, $dbPass) or die(“Couldn’t connect to database server: ” . mysql_error());
@mysql_select_db($dbName) or die(“Couldn’t connect to database: ” . mysql_error());
if($_POST[‘submit’] && $_FILES[‘attached’][‘name’][0] && $_FILES[‘attached’][‘name’][1] && $_FILES[‘attached’][‘name’][2])
{
$ok_filetypes = explode(“|”,$att_filetypes);
if (!$_FILES[‘attached’][‘error’] && $_FILES[‘attached’][‘size’] > $att_max_size*1024){
echo “<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[‘attached’][‘error’] ? substr( basename($_FILES[‘attached’][‘name’][0]), -30 ) : ”);
$filename1 = (!$_FILES[‘attached’][‘error’] ? substr( basename($_FILES[‘attached’][‘name’][1]), -30 ) : ”);
$filename2 = (!$_FILES[‘attached’][‘error’] ? substr( basename($_FILES[‘attached’][‘name’][2]), -30 ) : ”);
$x = strtolower( substr($_FILES[‘attached’][‘name’][0], -3));
$x1 = strtolower( substr($_FILES[‘attached’][‘name’][1], -3));
$x2 = strtolower( substr($_FILES[‘attached’][‘name’][2], -3));
if($filename && !in_array($x, $ok_filetypes) ){
echo “<CENTER>Sorry, the filetype you have tried to upload is not allowed.</CENTER><BR><BR>”;
$step = 1;
}
if($filename1 && !in_array($x1, $ok_filetypes) ){
echo “<CENTER>Sorry, the filetype you have tried to upload is not allowed.</CENTER><BR><BR>”;
$step = 1;
}
if($filename2 && !in_array($x2, $ok_filetypes) ){
echo “<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 );
$uniq1 = substr( md5(uniqid (rand())), 0, 10 );
$uniq2 = substr( md5(uniqid (rand())), 0, 10 );
$ext = strtolower( substr($_FILES[‘attached’][‘name’][0], -3));
$ext1 = strtolower( substr($_FILES[‘attached’][‘name’][1], -3));
$ext2 = strtolower( substr($_FILES[‘attached’][‘name’][2], -3));
move_uploaded_file($_FILES[‘attached’][‘tmp_name’][0], $att_path.”/”.$uniq.”.”.$ext );
move_uploaded_file($_FILES[‘attached’][‘tmp_name’][1], $att_path.”/”.$uniq1.”.”.$ext1 );
move_uploaded_file($_FILES[‘attached’][‘tmp_name’][2], $att_path.”/”.$uniq2.”.”.$ext2 );
$strQuery = “INSERT INTO images SET “;
$strQuery .= “filename='”.$uniq.”.”.$ext.”‘,”;
$strQuery .= “ipaddress='{$ipaddress}’,”;
$strQuery .= “date='”.time().”‘,”;
$strQuery .= “pkey='{$uniq}’,”;
$strQuery1 = “INSERT INTO images SET “;
$strQuery1 .= “filename='”.$uniq1.”.”.$ext1.”‘,”;
$strQuery1 .= “ipaddress='{$ipaddress}’,”;
$strQuery1 .= “date='”.time().”‘,”;
$strQuery1 .= “pkey='{$uniq1}’,”;
$strQuery2 = “INSERT INTO images SET “;
$strQuery2 .= “filename='”.$uniq2.”.”.$ext2.”‘,”;
$strQuery2 .= “ipaddress='{$ipaddress}’,”;
$strQuery2 .= “date='”.time().”‘,”;
$strQuery2 .= “pkey='{$uniq2}’,”;
//$strQuery = “INSERT INTO images(filename,ipaddress,date,pkey) VALUES($uniq.”.”.$ext,$ipaddress,'”.time().”‘,$uniq)”;
if($myuid){
$strQuery .= “user='{$myuid}’,”;
$strQuery1 .= “user='{$myuid}’,”;
$strQuery2 .= “user='{$myuid}’,”;
}
$strQuery .= “status=’1′”;
$strQuery1 .= “status=’1′”;
$strQuery2 .= “status=’1′”;
$result = mysql_query($strQuery) or die( mysql_error() );
$result1 = mysql_query($strQuery1) or die( mysql_error() );
$result2 = mysql_query($strQuery2) or die( mysql_error() );
$aid = mysql_insert_id();
// $aid1 = mysql_insert_id();
if($aid){
$filen = $siteurl.”/”.str_replace(‘./’, ”, $att_path).”/”.$uniq.”.”.$ext;
$filen = str_replace(‘http://’,’%%’,$filen);
$filen = str_replace(‘//’,’/’,$filen);
$filen = str_replace(‘%%’,’http://’,$filen);
$filen1 = $siteurl.”/”.str_replace(‘./’, ”, $att_path).”/”.$uniq1.”.”.$ext1;
$filen1 = str_replace(‘http://’,’%%’,$filen1);
$filen1 = str_replace(‘//’,’/’,$filen1);
$filen1 = str_replace(‘%%’,’http://’,$filen1);
$filen2 = $siteurl.”/”.str_replace(‘./’, ”, $att_path).”/”.$uniq2.”.”.$ext2;
$filen2 = str_replace(‘http://’,’%%’,$filen2);
$filen2 = str_replace(‘//’,’/’,$filen2);
$filen2 = str_replace(‘%%’,’http://’,$filen2);
$step = 2;
}else{
$step = 1;
}
}
}else{
$step = 1;
}
if($step == 1){
?>
<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″>
<INPUT NAME=”attached[]” TYPE=”file” size=”50″><br><br>
<INPUT NAME=”attached[]” TYPE=”file” size=”50″><br><br>
<INPUT NAME=”attached[]” TYPE=”file” size=”50″><br><br>
<input type=”submit” name=”submit” value=”submit”>
</form>
</div>
</td>
</tr>
</table>
<?
}else{ ?>
<div align=”center”>
<br>
</div>
<table width=”85%” border=”0″ align=”center” cellpadding=”0″ cellspacing=”0″>
<tr>
<td><div align=”center”>
<img src=”<?=$filen?>”> <img src=”<?=$filen1?>”> <img src=”<?=$filen2?>”>
</div></td>
</tr>
<tr>
<td><div align=”center”><br>
<textarea name=”textarea” cols=”100″ wrap=”soft” rows=”3″>
[url=<?=$siteurl?>][img]<?=$filen?>[/img][/url]
[url=<?=$siteurl?>][img]<?=$filen1?>[/img][/url]
[url=<?=$siteurl?>][img]<?=$filen2?>[/img][/url]
</textarea>
</div></td>
</tr>
<tr>
<td><div align=”center”><br>
<textarea name=”textarea2″ cols=”100″ rows=”4″><?=$filen?><?=$filen1?><?=$filen2?>
</textarea>
</div></td>
</tr>
<tr>
<td><div align=”center”><br>
<br>
<textarea name=”textarea3″ cols=”100″ wrap=”soft” rows=”3″>
<a href=”<?=$siteurl?>” target=”_blank”>
<img alt=”Image Hosted by <?=$sitename?>” src=”<?=$filen?>” /></a>
<a href=”<?=$siteurl?>” target=”_blank”>
<img alt=”Image Hosted by <?=$sitename?>” src=”<?=$filen1?>” /></a>
<a href=”<?=$siteurl?>” target=”_blank”>
<img alt=”Image Hosted by <?=$sitename?>” src=”<?=$filen2?>” /></a>
</textarea>
</div></td>
</tr>
<tr>
<td> </td>
</tr>
</table>
<? } ?>