Member Avatar for fatihpiristine

everything works fine... i upload any picture or file that i allowed
the things is, i want to add uploading progress

any ideas??

here is my code....

<?php
//--------------------------------------------------------------------------------
$path = "";
$web = "../uploads/";
$nopic = "nopic.jpg";
$ad = "add_item";
$no = "1";
$page = $ad.$no;
//--------------------------------------------------------------------------------
$isim = $_REQUEST['NewsID'];
$tip = $_FILES[img1][type];
$size = $_FILES[img1][size];
//--------------------------------------------------------------------------------
$Edit = $_COOKIE['Edit'.$no];
if($Edit != "")
{
$GetID = "select * from news where NewsID='" . $isim . "'";
$FindID=mysql_query($GetID);
while($WriteID = mysql_fetch_array($FindID))
{
	if($WriteID['Resim'.$no] != "")
	{
	setcookie('Edit'.$no,'');
	$dosya = $WriteID['Resim'.$no];
	}
	else
	{
	setcookie('Edit'.$no,'');
	$dosya = $nopic;
	}
}
}
//--------------------------------------------------------------------------------
elseif($size >= 150000)
{
	$dosya = $nopic;
	//Temizle
	$sil1 = $isim."_".$no.".jpg";
	$sil2 = $isim."_".$no.".png";
	$sil3 = $isim."_".$no.".gif";
	@unlink($path.$sil1);
	@unlink($path.$sil2);
	@unlink($path.$sil3);
	$uyari = "<small>Max 150Kb</small>";
}
//--------------------------------------------------------------------------------
elseif($tip == "image/jpeg" || $tip == "image/pjpeg")
{
	$dosya = $isim."_".$no.".jpg";
	//Temizle
	$sil1 = $isim."_".$no.".jpg";
	$sil2 = $isim."_".$no.".png";
	$sil3 = $isim."_".$no.".gif";
	@unlink($path.$sil1);
	@unlink($path.$sil2);
	@unlink($path.$sil3);
	$query = "update news set Resim". $no ." ='" . $dosya . "' where NewsID=". $isim ."";
	mysql_query($query) or die(mysql_error());
	@copy($_FILES[img1][tmp_name],$path.$dosya);

}
//--------------------------------------------------------------------------------
elseif($tip == "image/png" || $tip == "image/x-png")
{
	$dosya = $isim."_".$no.".png";
	//Temizle
	$sil1 = $isim."_".$no.".jpg";
	$sil2 = $isim."_".$no.".png";
	$sil3 = $isim."_".$no.".gif";
	@unlink($path.$sil1);
	@unlink($path.$sil2);
	@unlink($path.$sil3);
	$query = "update news set Resim". $no ." ='" . $dosya . "' where NewsID=". $isim ."";
	mysql_query($query) or die(mysql_error());
	@copy($_FILES[img1][tmp_name],$path.$dosya);
}
//--------------------------------------------------------------------------------
elseif($tip == "image/gif")
{
	$dosya = $isim."_".$no.".gif";
	$sil1 = $isim."_".$no.".jpg";
	$sil2 = $isim."_".$no.".png";
	$sil3 = $isim."_".$no.".gif";
	@unlink($path.$sil1);
	@unlink($path.$sil2);
	@unlink($path.$sil3);
	$query = "update news set Resim". $no ." ='" . $dosya . "' where NewsID=". $isim ."";
	mysql_query($query) or die(mysql_error());
	@copy($_FILES[img1][tmp_name],$path.$dosya);
}
//--------------------------------------------------------------------------------
elseif($tip == "" )
{
	$dosya = $nopic;
}
//--------------------------------------------------------------------------------
elseif($tip != "image/jpeg" || $tip != "image/pjpeg" || $tip != "image/png" || $tip != "image/x-png" || $tip != "image/gif" || $tip != "")
{
	$dosya = $nopic;
	$uyari = "<small>Invalid file type</small>";
}
//--------------------------------------------------------------------------------
?>
<?php
$Delete = $_GET['Delete'];
$FileName = $_GET['FileName'];
if($Delete == "OK")
{
	$query = "update news set Resim". $no ." ='' where NewsID=". $isim ."";
	mysql_query($query) or die(mysql_error());
	@unlink($path.$FileName);
	$dosya = $nopic;
}
?>
<html>
<script language=JavaScript src='../js/controls.js'></script>
<script language="javascript">
// on loading show this picture
document.write('<div id="loading"><table align="center" border="0" cellpadding="0" cellspacing="0" width="100%"><tr><td align="center" height="100%"><br><img src="../images/loading.gif" alt="" align="middle"><br>Lütfen bekleyin...</td></tr></table></div>');

window.onload=function()
{
	document.getElementById("loading").style.display="none";
}
</script>
<body topmargin="0" leftmargin="0">
<form  method="post" action="<?php print $page ?>.php" enctype="multipart/form-data">
<table width="90" border="0" cellspacing="0" cellpadding="0">
<tr>
	<td align="center">
	<img name="img1" src="<?php if($dosya == $nopic) { print $dosya; } else { print $web.$dosya; } ?>" width="85" height="85">
	<?php if($dosya != $nopic) { $_POST[$dosya]; print "<br><a onclick='return resim_sil()' href=$page.php?Delete=OK&FileName=$dosya>Resmi Sil</a>&nbsp;"; } ?>
	<?php if($dosya == $nopic) { print $uyari;} ?>&nbsp;<br>
	</td>
</tr>
<tr>
<td>
<input type="file" name="img1"  accept="image/gif,image/jpeg,image/png" onChange="LimitAttach(this.form, this.form.img1.value)" size="1" style="width:80; border:none;">
</td>
</tr>
</table>
</form>
</body>
</html>

I think AJAX can solve your problem...

Member Avatar for fatihpiristine

I think AJAX can solve your problem...

i dont need ajax... there are many examples made with php, but i dont like to copy and paste into my code...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.