Page 1 of 1

image file can't display after uploaded

Posted: Fri Mar 14, 2008 10:40 pm
by blueshines
Hope someone can help me on this, when I uploaded the file, the file is not there, but the filename successfully updated in the MySQL Database, may I know what could be the problem?

Attached is the screenshot of the error.

Btw, below is the coding for product edit and product show:

product_edit.php
<?
include("inc/config.php");

if ($choice <> ""){

unlink( "/home/tohtonku.com.my/htdocs/upload/product/" . $photo);

if ($picture==1){
$sql = "update tbl_product2 set pic_product='nophoto150.gif' where id_2='$id_2'";
}
else if($picture==2){
$sql = "update tbl_product2 set pic_product1='nophoto300.gif' where id_2='$id_2'";
}
mysql_query( $sql );
}
else{

if ($name_product <> ""){

$strSQL = "SELECT * FROM tbl_product2 where name_product <> '$product'";
$result = mysql_query($strSQL,$conn);
$no = 0;

while($rs = mysql_fetch_array($result))
{
if ($name_product == $rs[name_product]){
$no = 1;
}
}

if ($no == 1){
$errormsg = "This Product Name already exist. Please key in again.";
}
else{

$file_upload = "true";

if($picproduct){

if ($picproduct_size >550000){
$errormsg=$errormsg."Your main photo file size is more than 550KB so please reduce the file size and then upload.<BR>";
$file_upload="false";
}

if (!($picproduct_type =="image/pjpeg" OR $picproduct_type=="image/gif")){
$errormsg=$errormsg."Your main photo file must be of JPG or GIF. Other file types are not allowed<BR>";
$file_upload="false";
}

if ($file_upload == "true"){
$main_img_path = "/home/tohtonku.com.my/htdocs/upload/product/$picproduct_name";

if(move_uploaded_file ($picproduct, $main_img_path)){
$sql = "update tbl_product2 set pic_product='$picproduct_name' where id_2='$id_2'";
mysql_query($sql);

}else{
echo "Failed to upload file Contact Site admin to fix the problem";
}
}
}


$file_upload1 = "true";

if($picproduct1){

if ($picproduct1_size >550000){
$errormsg=$errormsg."Your main photo file size is more than 550KB so please reduce the file size and then upload.<BR>";
$file_upload1="false";
}

if (!($picproduct1_type =="image/pjpeg" OR $picproduct1_type=="image/gif")){
$errormsg=$errormsg."Your main photo file must be of JPG or GIF. Other file types are not allowed<BR>";
$file_upload1="false";
}

if ($file_upload1 == "true"){
$main_img_path = "/home/tohtonku.com.my/htdocs/upload/product/$picproduct1_name";

if(move_uploaded_file ($picproduct1, $main_img_path)){
$sql = "update tbl_product2 set pic_product1='$picproduct1_name' where id_2='$id_2'";
mysql_query($sql);

}else{
echo "Failed to upload file Contact Site admin to fix the problem";
}
}
}


if (errormsg <> ""){
$sql = "update tbl_product2 set name_product='$name_product' where id_2='$id_2'";
mysql_query($sql);

if ($picproduct){
$sql1 = "update tbl_product2 set pic_product='$picproduct_name' where id_2='$id_2'";
mysql_query($sql1);
}

if ($picproduct1){
$sql2 = "update tbl_product2 set pic_product1='$picproduct1_name' where id_2='$id_2'";
mysql_query($sql2);
}

$sql3 = "update tbl_product2 set note_product='$note_product' where id_2='$id_2'";
mysql_query($sql3);

$sql4 = "update tbl_product2 set price='$price' where id_2='$id_2'";
mysql_query($sql4);

$sql5 = "update tbl_product2 set post_date=now() where id_2='$id_2'";
mysql_query($sql5);

header("location:show.php?id=$id&id_1=$id_1&id_sub=$id_sub");
}
}
}
}
?>

<html>
<head>
<title>Tohtonku Web Administration</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">

<style type="text/css">
<!--
.title {
font-family: "MS Sans Serif", Tahoma, sans-serif;
font-size: 13px;
text-decoration: none;
color:#FFFFFF;
}

.smallTitle {
font-family: "MS Sans Serif", Tahoma, sans-serif;
font-size: 13px;
text-decoration: none;
color:black;
}

-->
</style>

<SCRIPT LANGUAGE="JavaScript1.2">
function gotoP(vPage){
location.href = vPage;
}

function chk(){
if(document.form1.name_product.value==''){
alert('Please fill in product name.');
document.form1.name_product.focus();
}
else if(document.form1.price.value==''){
alert('Please fill in product price');
document.form1.price.focus();
}
else if(isNaN(document.form1.price.value) == true){
alert('Only digit is allow in the price');
document.form1.price.focus();
}
else{
document.form1.submit();
}
}

</SCRIPT>

</head>

<body>
<?
$strSQL = "SELECT * FROM product_name where id='$id'";
$result = mysql_query($strSQL,$conn);

while($rs = mysql_fetch_array($result))
{
$proName = $rs[product_name];
}

$strSQL = "SELECT * FROM tbl_product1 where id_1='$id_1'";
$result = mysql_query($strSQL,$conn);

while($rs = mysql_fetch_array($result))
{
$proCat = $rs[name];
}

$strSQL = "SELECT * FROM sub_product where id_sub='$id_sub'";
$result = mysql_query($strSQL,$conn);

while($rs = mysql_fetch_array($result))
{
$proSub = $rs[sub_name];
}

$strSQL = "SELECT * FROM tbl_product2 where id_2='$id_2'";
$result = mysql_query($strSQL,$conn);

while($rs = mysql_fetch_array($result))
{
$product = $rs[name_product];
}

?>

<img src="images/admin/logo.jpg"><p><b><font face="Arial">>> Edit Product Detail (<? echo $proName; ?> > <? echo $proCat; ?> > <? echo $proSub; ?> > <? echo $product; ?>)</font>

</b></p>
<table width="800" border="0" cellspacing="0" cellpadding="0">
<tr><td bgcolor="#666666" height="2"><img src="images/blank.gif" width="1" height="1"></td></tr></table>
<br>

<form action="product_edit.php" method="post" name="form1" enctype="multipart/form-data" >
<input type="hidden" name="id" value="<? echo $id; ?>">
<input type="hidden" name="id_1" value="<? echo $id_1; ?>">
<input type="hidden" name="id_2" value="<? echo $id_2; ?>">
<input type="hidden" name="id_sub" value="<? echo $id_sub; ?>">

<input type="hidden" name="product" value="<? echo $product; ?>">

<table width="800" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center">
<? echo $errormsg; ?>
<table width="630" border="0" cellpadding="2" cellspacing="1" bordercolor="#CCCCCC" bgcolor="#666666">
<tr bgcolor="#666666">
<td colspan="2" align="center" class="title"><strong>Edit Product Detail</strong></td>
</tr>


<?
$strSQL = "SELECT * FROM tbl_product2 where id_2='$id_2'";
$result = mysql_query($strSQL,$conn);

while($rs = mysql_fetch_array($result))
{
$name_product = $rs[name_product];
$pic_product = $rs[pic_product];
$pic_product1 = $rs[pic_product1];
$price = $rs[price];
$note_product = $rs[note_product];
}
?>

<tr bgcolor="#CCCCCC">
<td class="smallTitle">Product Name</td>
<td ><input name="name_product" type="text" id="name_product" value="<? echo $name_product; ?>"><font color="#FF0000">*</font></td>
</tr>
<tr bgcolor="#CCCCCC">
<td class="smallTitle">Product Picture (s)</td>
<td>

<table width=200>
<tr>
<td width=50%>
<img src='../upload/product/<? echo $pic_product; ?>' width=200 height=150>
</td>
<td width=50% align="right">
<?
if ($pic_product=="nophoto150.gif"){
echo "<input type=file name='picproduct'>";
}else{
?>
<input type=button name=removeMain value=Remove onClick="gotoP('product_edit.php?id_2=<? echo $id_2; ?>&id_1=<? echo $id_1; ?>&id_sub=<? echo $id_sub; ?>&id=<? echo $id; ?>&photo=<? echo $pic_product; ?>&picture=1&choice=remove')">
<?
}
?>

</td>
</tr>
</table>
</td>
</tr>
<tr bgcolor="#CCCCCC">
<td class="smallTitle">Product Picture (b)</td>
<td>
<table width=200>

<tr>
<td width=50%>
<img src='../upload/product/<? echo $pic_product1; ?>' width=200 height=150>
</td>
<td width=50% align="right">
<?
if ($pic_product1=="nophoto300.gif"){
echo "<input type=file name='picproduct1'>";
}else{
?>
<input type=button name=removeMain value=Remove onClick="gotoP('product_edit.php?id_2=<? echo $id_2; ?>&id_1=<? echo $id_1; ?>&id_sub=<? echo $id_sub; ?>&id=<? echo $id; ?>&photo=<? echo $pic_product1; ?>&picture=2&choice=remove')">
<?
}
?>
</td>

</tr>
</table>
</td>
</tr>
<tr bgcolor="#CCCCCC">
<td class="smallTitle">Product Price</td>
<td class="smallTitle">RM <input name="price" type="text" id="price" value="<? echo $price; ?>">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<b><font size=1>(* Price is not showing at front page)</font></b></td>

</tr>
<tr bgcolor="#CCCCCC">
<td class="smallTitle">Description</td>
<td>
<textarea name="note_product" id="note_product" cols=80 rows=10><? echo $note_product; ?></textarea></td>
</tr>
<tr bgcolor="#CCCCCC">
<td >&nbsp;</td>

<td align="center"><input type="button" name="Submit" value="EDIT" style="width:80;" onclick="chk();">&nbsp;&nbsp;&nbsp;<input type="button" onclick="gotoP('show.php?id=<? echo $id; ?>&id_1=<? echo $id_1; ?>&id_sub=<? echo $id_sub; ?>')" value="CANCEL" style="width:80;"></td>
</tr>
</table>
</td>
</tr>
</table>
</form>

</body>
</html>


product_show.php

<?
include("inc/config.php");
?>

<html>
<head>
<title>Tohtonku Web Administration</title>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874">
<style type="text/css">
<!--
.pro {
font-family: "MS Sans Serif", Tahoma, sans-serif;
font-size: 14px;
text-decoration: none;
color: black;
}

a:hover{
text-decoration: underline;
}
-->
</style>

<SCRIPT LANGUAGE="JavaScript1.2">
function gotoP(vPage){
parent.location.href = vPage;
}

function gotoP1(vPage){
location.href = vPage;
}

</SCRIPT>

</head>

<body>
<img src="images/admin/logo.jpg"><p><b><font face="Arial">>> Product Detail</font>

</b></p>
<table width="800" border="0" cellspacing="0" cellpadding="0">
<tr><td bgcolor="#666666" height="2"><img src="images/blank.gif" width="1" height="1"></td></tr></table>
<br>
<table width=800 border="0">
<tr>
<td>
<p align="right">
<input class="btnMail" type="button" onClick="gotoP1('show.php?id=<? echo $id; ?>&id_1=<? echo $id_1; ?>&id_sub=<? echo $id_sub;?>')" value="+ Back" style="width:130;" name="button">&nbsp&nbsp&nbsp

<input class="btnMail" type="button" onClick="gotoP1('admin.php')" value="+ Administration" style="width:130;" name="button">&nbsp&nbsp&nbsp
<input class="btnMail" type="button" onClick="gotoP('logout.php')" value="+ Logout" style="width:130;" name="button"></td>
</tr>
<tr><td colspan=3>&nbsp;</td></tr>
<tr><td align="right">
<table width="500" border="0" align="center">
<?
$strSQL = "SELECT * FROM tbl_product2 where id_2='$id_2' and id_1='$id_1' and id_product='$id' and id_sub='$id_sub' ";
$result = mysql_query($strSQL,$conn);
while($rs = mysql_fetch_array($result))
{
?>
<tr bgcolor="#333333">
<td colspan="2" align="center" height="25"><strong><font color="#FFFFFF" size="2" face="MS Sans Serif, Tahoma, sans-serif"><? echo"$rs[name_product]"; ?></strong></font></td>

</tr>
<tr bgcolor="#CCCCCC">
<td width="150" class="pro" align="center" valign="middle"><b>Picture(s)</b></td>
<td width="350" class="pro" align="center" valign="middle"><br><img src="../upload/product/<?=$rs[pic_product]?>" border="0"><br><?=$rs[pic_product]?><br><br></td>
</tr>
<tr bgcolor="#CCCCCC">
<td width="150" class="pro" align="center" valign="middle"><b>Picture(b)</b></td>
<td width="350" class="pro" align="center" valign="middle"><br><img src="../upload/product/<?=$rs[pic_product1]?>" border="0"><br><?=$rs[pic_product1]?><br><br></td>
</tr>

<tr bgcolor="#CCCCCC">
<td width="150" class="pro" align="center" valign="middle"><b>Price</b></td>
<td width="350" class="pro" align="left" valign="middle">RM <? echo"$rs[price]"; ?></font>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<b><font size=1>(* Price is not showing at front page)</font></b></td>
</tr>
<tr bgcolor="#CCCCCC">
<td width="150" class="pro" align="center" valign="middle"><b>Description</b></td>
<td width="350" class="pro" align="left" valign="middle"><? echo"$rs[note_product]"; ?><br><br></font></td>
</tr>

<?
}
?>
</table>
</td> </tr>
</table>

</body>
</html>

Thanks and hope can find the solutions ASAP.

Regard,

Re: image file can't display after uploaded

Posted: Fri Mar 14, 2008 11:29 pm
by yacahuma
i dont see any screenshots. Anyway did you check the permissions? Are you running opn windows or unix?

Re: image file can't display after uploaded

Posted: Sat Mar 15, 2008 12:48 pm
by blueshines
It's running under Unix, may I know where to set the permission? Is it at the script that upload the file or script that display the file? I've tried to add, but it seems not working. Can you provide me the sample code?

Thanks.