darubillah Posted June 24, 2010 Share Posted June 24, 2010 hello, I need a little help I am working on a script the code below uploads an image file, and rename it to Users Id.png, It was working fine on my localhost, But when I uploaded it on my Hostgator account but now it doesn't upload images dont know why plzzz help me if($_POST["file"]!="") { //Uploading Avatar START if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 200000000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { if (file_exists("uploads/avatar/" . $id.".png")) { //if used ids.png file already exist then delete it first $path_to_profile_imgs="/public_html/pakmoneymatrix.com/new/uploads/avatar/"; $profile_pic_name = $id.".png"; unlink($path_to_profile_imgs.$profile_pic_name); //Now Upload file move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/avatar/" . $id .".png"); } } } else { echo "<center><div class=\"error\">Your Profile Avatar cant be updated, Please <a href=\"contact.php\">Report us</a> about this problem!</div></center><br />"; } } Best Regards! Quote Link to comment https://forums.phpfreaks.com/topic/205752-image-uploading-problem-working-on-localhost-but-not-on-server/ Share on other sites More sharing options...
Adam Posted June 24, 2010 Share Posted June 24, 2010 What version of PHP is on your local and remote host? Quote Link to comment https://forums.phpfreaks.com/topic/205752-image-uploading-problem-working-on-localhost-but-not-on-server/#findComment-1076711 Share on other sites More sharing options...
kenrbnsn Posted June 24, 2010 Share Posted June 24, 2010 Do you get any errors? Ken Quote Link to comment https://forums.phpfreaks.com/topic/205752-image-uploading-problem-working-on-localhost-but-not-on-server/#findComment-1076712 Share on other sites More sharing options...
darubillah Posted June 24, 2010 Author Share Posted June 24, 2010 its giving no error dont know the php version Quote Link to comment https://forums.phpfreaks.com/topic/205752-image-uploading-problem-working-on-localhost-but-not-on-server/#findComment-1076719 Share on other sites More sharing options...
Adam Posted June 24, 2010 Share Posted June 24, 2010 Actually I can't really see anything that would cause problems between any versions 4+. Looking at your logic though, it seems unless the image exists already you don't 'move uploaded file'. I think you should close that IF after the unlink... Quote Link to comment https://forums.phpfreaks.com/topic/205752-image-uploading-problem-working-on-localhost-but-not-on-server/#findComment-1076721 Share on other sites More sharing options...
PFMaBiSmAd Posted June 24, 2010 Share Posted June 24, 2010 For debugging purposes (remove them when you are done), to see if there are any php detected errors, add the following two lines of code immediately after your first opening <?php tag - ini_set("display_errors", "1"); error_reporting(E_ALL); Quote Link to comment https://forums.phpfreaks.com/topic/205752-image-uploading-problem-working-on-localhost-but-not-on-server/#findComment-1076724 Share on other sites More sharing options...
darubillah Posted June 24, 2010 Author Share Posted June 24, 2010 i try remving unlink function, removing if statement as MrAdam said, After adding debugging I am getting this Notice: Undefined index: file in /home/usrename/public_html/update_pf.php on line 98 line 98 has this code if($_POST["file"]!="") { Quote Link to comment https://forums.phpfreaks.com/topic/205752-image-uploading-problem-working-on-localhost-but-not-on-server/#findComment-1076731 Share on other sites More sharing options...
Adam Posted June 24, 2010 Share Posted June 24, 2010 I didn't say remove the unlink function, I meant close the IF block after the unlunk function: if (file_exists("uploads/avatar/" . $id.".png")) { //if used ids.png file already exist then delete it first $path_to_profile_imgs="/public_html/pakmoneymatrix.com/new/uploads/avatar/"; $profile_pic_name = $id.".png"; unlink($path_to_profile_imgs.$profile_pic_name); } //Now Upload file move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/avatar/" . $id .".png"); The notice you're seeing isn't strictly an error, it's just telling you that you're trying to use $_POST["file"] without first ensuring it exists. empty implicitly performs an isset check and does exactly what you need: if (!empty($_POST["file"])) { Quote Link to comment https://forums.phpfreaks.com/topic/205752-image-uploading-problem-working-on-localhost-but-not-on-server/#findComment-1076735 Share on other sites More sharing options...
PFMaBiSmAd Posted June 24, 2010 Share Posted June 24, 2010 Either your form is doing something that is php version/configuration specific and is invalid (unlikely) or the total size of the form data exceeds the post_max_size setting (fairly likely). What does a phpinfo(); statement show for post_max_size setting and what size of a file did you attempt to upload? Quote Link to comment https://forums.phpfreaks.com/topic/205752-image-uploading-problem-working-on-localhost-but-not-on-server/#findComment-1076738 Share on other sites More sharing options...
darubillah Posted June 24, 2010 Author Share Posted June 24, 2010 after adding if (!empty($_POST["file"])) { php debug is not gving error but its also not uploading its showing 64M in post_max_size when i am moving folder do i have to write whole path like home/usrname/public_html/.... or simply the path from the root move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/avatar/" . $id .".png"); Quote Link to comment https://forums.phpfreaks.com/topic/205752-image-uploading-problem-working-on-localhost-but-not-on-server/#findComment-1076743 Share on other sites More sharing options...
Adam Posted June 24, 2010 Share Posted June 24, 2010 Did you try the code I posted? Quote Link to comment https://forums.phpfreaks.com/topic/205752-image-uploading-problem-working-on-localhost-but-not-on-server/#findComment-1076747 Share on other sites More sharing options...
darubillah Posted June 24, 2010 Author Share Posted June 24, 2010 yap your code also dont work Quote Link to comment https://forums.phpfreaks.com/topic/205752-image-uploading-problem-working-on-localhost-but-not-on-server/#findComment-1076749 Share on other sites More sharing options...
darubillah Posted June 24, 2010 Author Share Posted June 24, 2010 Is their any direct way to upload images directly in to uploads/avatar folder like in above logic we are first uploading images in the temp dir. and then moving it from temp to uploads/avatar Quote Link to comment https://forums.phpfreaks.com/topic/205752-image-uploading-problem-working-on-localhost-but-not-on-server/#findComment-1076751 Share on other sites More sharing options...
PFMaBiSmAd Posted June 24, 2010 Share Posted June 24, 2010 SLOW DOWN (everyone). Your whole php code is being skipped over because $_POST['file'] does not exist. If your code worked on your development system (which I doubt at this point), but not now, something is preventing that post variable from being set. Start by posting all your code, including the form. Quote Link to comment https://forums.phpfreaks.com/topic/205752-image-uploading-problem-working-on-localhost-but-not-on-server/#findComment-1076757 Share on other sites More sharing options...
darubillah Posted June 24, 2010 Author Share Posted June 24, 2010 Here the whole code <?php ini_set("display_errors", "1"); error_reporting(E_ALL); session_start(); session_register("id_session"); session_register("password_session"); include "header.php"; include "customMenu.php"; $id=$_SESSION["id_session"]; $password=$_SESSION["password_session"]; if ($id=="" && $password=="") { ?> <script> var RecaptchaOptions = { theme : 'blackglass' }; </script> <form action=members.php method=post><br /><center> <table> <tr> <td width=25%></td> <td valign="middle"><img src="images/login.png" alt="Log into <? echo $sitename; ?>" /></td> <td><h2>Member's Area</h2></td> </tr> </table> <table width=50%> <tr> <td width=20%></td> <td width=33%>Member's ID</td><td><input type=text name=id></td></tr> <tr> <td></td> <td>Password</td><td><input type=password name=password></td></tr> </table> <table align="center"> <tr> <td align="center"> <?php require_once('recaptchalib.php'); $publickey = "6Le4SboSAAAAAORd5lhQBwJVERfrtinzF5QF48aY"; // you got this from the signup page echo recaptcha_get_html($publickey); ?> <FONT face=Arial,Helvetica,Geneva,Sans-serif,sans-serif size=-1><small> Please Enter The Characters you see in the image.</small></FONT> </td> </tr> <tr> <td align="center"> <a href="forgot.php" onclick="doexit=false;"><small><strong>Forgot Your Password?</strong></small></a> </td> </tr> </table> <table width="100%"> <tr> <td width="40%"></td> <td> <div class="buttons"> <button type="submit" class="positive"> <img src="images/textfield_key.png" alt="Login To <? echo $sitename; ?>"/> Login </button> </div> </td> </tr> </table></form> <? } else { if (!$_POST) { middle(); } elseif ($_POST["fname"]!="" && $_POST["add"]!="" && $_POST["city"]!="" && $_POST["state"]!="" && $_POST["country"]!="" && $_POST["pzcode"]!="" && $_POST["pwd"]!="") { if($password==$_POST["pwd"]) { print "<center><div class=\"success\">Your Account has been updated successfully</div></center><br />"; $id=$_SESSION["id_session"]; if (!empty($_POST["file"])) { //Uploading Avatar START if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/pjpeg")) && ($_FILES["file"]["size"] < 200000000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { if (file_exists("uploads/avatar/" . $id.".png")) { //if used ids.png file already exist then delete it first $path_to_profile_imgs="/public_html/pakmoneymatrix.com/new/uploads/avatar/"; $profile_pic_name = $id.".png"; unlink($path_to_profile_imgs.$profile_pic_name); } //Now Upload file move_uploaded_file($_FILES["file"]["tmp_name"], "uploads/avatar/" . $id .".png"); } } else { echo "<center><div class=\"error\">Your Profile Avatar cant be updated, Please <a href=\"contact.php\">Report us</a> about this problem!</div></center><br />"; } } //Uploading Avatar END $rs = mysql_query("select * from members where ID=$id"); $arr=mysql_fetch_array($rs); $check=0; $check=1; $db_field[1]=$_POST["fname"]; $db_field[2]=$_POST["add"]; $db_field[3]=$_POST["city"]; $db_field[4]=$_POST["state"]; $db_field[5]=$_POST["pzcode"]; $db_field[6]=$_POST["country"]; $db_field[7]=$_POST["changepass"]; if($db_field[7]!="") { $query="update members set Name='$db_field[1]', Address='$db_field[2]', City='$db_field[3]', State='$db_field[4]', Zip='$db_field[5]', Country='$db_field[6]', Password='$db_field[7]' where ID=$id"; } else { $query="update members set Name='$db_field[1]', Address='$db_field[2]', City='$db_field[3]', State='$db_field[4]', Zip='$db_field[5]', Country='$db_field[6]' where ID=$id"; } $rs = mysql_query($query); } else { print "<center><div class=\"error\">Invalid Password ! Account cannot be updated!</div></center></div>"; } middle(); } } ?> <br><br> <? include "footer.php"; function middle() { include "config.php"; $id=$_SESSION["id_session"]; $rs = mysql_query("select * from members where ID=$id"); $arr=mysql_fetch_array($rs); $name=$arr['Name']; $address=$arr['Address']; $city=$arr['City']; $state=$arr['State']; $zip=$arr['Zip']; $country=$arr['Country']; $password=$arr['Password']; $email=$arr['Email']; ?> <?php include 'menu.php'; ?> <form method="post" action="update_pf.php" enctype="multipart/form-data"> <table> <tr> <td width=25%></td> <td valign="middle"><img src="images/Profile.png" alt="Update my <? echo $sitename; ?> Profile!" /></td> <td><h2>Update Profile</h2></td> </tr> </table><br /> <table width="400" border="0" cellspacing="0" cellpadding="0" align="center"> <tr align="left" valign="middle"> <td width="10%"></td> <td width="140"> <?php if (!is_file("uploads/avatar/".$id.".png")) { ?> <img class="roundleft" src="uploads/noavatar.jpg" width="140" height="150" alt="<? echo $name; ?> Profile Pic" /></td> <? } else { ?> <img class="roundleft" src="uploads/avatar/<? echo $id.".png" ?>" width="140" height="150" alt="<? echo $name; ?> Profile Pic" /></td> <? } ?> <td valign="top"><h1 align="center"> <? echo $name; ?>'s<br /><br />Profile </h1></td> </tr> </table> <table width="400" border="0" cellspacing="0" cellpadding="0" align="center"> <tr align="left" valign="middle"> <td width="10%"></td> <td width="44%"><b>FULL NAME*</b></td> <td width="56%" height="40"><b> <input type="text" name="fname" maxlength="40" value="<? echo $name; ?>"> </b></td> </tr> <tr align="left" valign="middle"> <td></td> <td width="44%" height="18"><b>EMAIL ADDRESS* </b></td> <td width="56%" height="40" align="left"><b> <? echo $email; ?> </b></td> </tr> <tr align="left" valign="middle"> <td></td> <td width="44%" height="18"><b>ADDRESS*</b></td> <td width="56%" height="40" align="left"><b> <input type="text" name="add" value="<? echo $address; ?>"> </b></td> </tr> <tr align="left" valign="middle"> <td></td> <td width="44%"><b>CITY*</b></td> <td width="56%" height="40" align="left"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2"> <input type="text" name="city" maxlength="30" value="<? echo $city; ?>"> </b></td> </tr> <tr align="left" valign="middle"> <td></td> <td height="18" width="44%"><b>STATE*</b></td> <td height="40" width="56%" align="left"><b> <input type="text" name="state" maxlength="30" value="<? echo $state; ?>"> </b></td> </tr> <tr align="left" valign="middle"> <td></td> <td height="18" width="44%"><b>COUNTRY*</b></td> <td height="40" width="56%" align="left"><b><font face="Verdana, Arial, Helvetica, sans-serif" size="2"> <input type="text" name="country" maxlength="30" value="<? echo $country; ?>"> </font></b></td> </tr> <tr align="left" valign="middle"> <td></td> <td width="44%"><b> ZIP CODE*</font></b></td> <td width="56%" height="40" align="left"><b> <input type="text" name="pzcode" maxlength="20" value="<? echo $zip; ?>"> </b></td> </tr> <tr align="left" valign="middle"> <td></td> <td width="44%"><b> PROFILE PIC</font></b></td> <td width="56%" height="40" align="left"><b> <input type="file" name="file" id="file" /> </b></td> </tr> <tr align="left" valign="middle"> <td></td> <td width="44%"><b> CHANGE PASSWORD</b></td> <td width="56%" height="40" align="left"><b> <input type="password" name="changepass" maxlength="20" value="<? echo $password; ?>"> </b></td> </tr> <tr align="left" valign="middle"> <td></td> <td width="44%"><b>CURRENT PASSWORD* </b></td> <td width="56%" height="40" align="left"><b> <input type="password" name="pwd" maxlength="40"> </b></td> </tr> </table> <table width="100%"> <tr> <td width="40%"></td> <td> <div class="buttons"> <button type="submit" class="positive"> <img src="images/validation/update.png" alt="Update My <? echo $sitename; ?> Profile!"/> Update </button> </div> </td> </tr> </table> </form> <? return 1; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/205752-image-uploading-problem-working-on-localhost-but-not-on-server/#findComment-1076761 Share on other sites More sharing options...
PFMaBiSmAd Posted June 24, 2010 Share Posted June 24, 2010 Your upload form does not have a field that sets $_POST['file'], so what was the if (!empty($_POST["file"])) { originally when the code worked on your development system? I'll guess it was $_FILES['file']? Quote Link to comment https://forums.phpfreaks.com/topic/205752-image-uploading-problem-working-on-localhost-but-not-on-server/#findComment-1076795 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.