upendra470 Posted July 11, 2011 Share Posted July 11, 2011 I have uploaded a folder on web for storing images. When I ran my php code to add images on localhost, it works perfectly fine but when i uploaded it on the web server, no image is produced inside the folder but it says 'image successfully added' Please help. Here is my addgallery.php code <?php include "session.php"; include "connect.php"; if(isset($_SERVER['CONTENT_LENGTH']) && $_SERVER['CONTENT_LENGTH']>8097152){ echo "<script type = 'text/javascript'>alert('Upload files is too large. Cannot add to the gallery'); window.location = 'gallery.php';</script>"; exit(); } else{ $n_width = 100; $n_height = 100; if(count($_FILES["image_id"]["name"]) > 0){ for($j=0; $j < count($_FILES["image_id"]["name"]); $j++){ if ((($_FILES["image_id"]["type"][$j] == "image/gif") || ($_FILES["image_id"]["type"][$j] == "image/jpeg") || ($_FILES["image_id"]["type"][$j] == "image/pjpeg")) && ($_FILES["image_id"]["size"][$j] < 40000000)) { if ($_FILES["image_id"]["error"][$j] > 0) { echo "Return Code: " . $_FILES["image_id"]["error"][$j] . "<br />"; } else { //echo "Upload: " . $_FILES["image_id"]["name"] . "<br />"; //echo "Type: " . $_FILES["image_id"]["type"] . "<br />"; //echo "Size: " . ($_FILES["image_id"]["size"] / 1024) . " Kb<br />"; // echo "Temp file: " . $_FILES["image_id"]["tmp_name"] . "<br />"; if (file_exists("upload/gallery/" . $_FILES["image_id"]["name"][$j])) { echo $_FILES["image_id"]["name"][$j] . " already exists. "; } else { move_uploaded_file($_FILES["image_id"]["tmp_name"][$j], "upload/gallery/" . $_FILES["image_id"]["name"][$j]); echo "Stored in: " . "upload/gallery/" . $_FILES["image_id"]["name"][$j]; /* $tsrc = "upload/thumbs/".$_FILES["image_id"]["name"][$j]; $im = imagecreatefromjpeg("upload/gallery/".$_FILES["image_id"]["tmp_name"][$j]); $width = imagesx($im); $height = imagesy($im); $newimage = imagecreatetruecolor($n_width,$n_height); //$background = imagecolorallocate($newimage,255,255,255); //imagecolortransparent($newimage, $background); //imagealphablending($newimage, false); //imagesavealpha($image, true); imagecopyresampled($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height); imagejpeg($newimage, $tsrc);*/ //chmod("$tsrc", 0777); } } } else { echo "Invalid file"; } } } } $category = $_POST['category']; $desc = $_POST['desc']; for($j=0; $j < count($_FILES["image_id"]["name"]); $j++){ $pic_name = $_FILES["image_id"]["name"][$j]; $sql= "insert into gallery (category, pic_desc, pic_name) values('$category', '$desc', '$pic_name')"; $result = mysql_query($sql) or die(mysql_error()); } if($result){ //echo "<h4 style='color:green;'>Picture uploaded sucessfully</h4>"; //echo "<meta http-equiv=\"refresh\" content=\"1;URL=gallery.php\" />"; header("location: galleryadded.php"); } else{ echo " Images cannot be added"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/241743-how-to-refer-to-the-uploaded-folder/ Share on other sites More sharing options...
AyKay47 Posted July 11, 2011 Share Posted July 11, 2011 This most likely has to do with the pathing used in your move_uploaded_file function...try using a relative path to the DOC_ROOT Quote Link to comment https://forums.phpfreaks.com/topic/241743-how-to-refer-to-the-uploaded-folder/#findComment-1241613 Share on other sites More sharing options...
teynon Posted July 11, 2011 Share Posted July 11, 2011 You are not confirming that the file is copying. You should have an if on your move uploaded file: if (move_uploaded_file(FILESTUFF)) { Success } else { FAIL } Your most likely issue is that you haven't chmodded the upload folder. Quote Link to comment https://forums.phpfreaks.com/topic/241743-how-to-refer-to-the-uploaded-folder/#findComment-1241617 Share on other sites More sharing options...
upendra470 Posted July 12, 2011 Author Share Posted July 12, 2011 Nothing works. Can you tell me the exact path or exact correction i need to make in this code. I have been trying for so long but still not got anything positive. Quote Link to comment https://forums.phpfreaks.com/topic/241743-how-to-refer-to-the-uploaded-folder/#findComment-1241769 Share on other sites More sharing options...
AyKay47 Posted July 12, 2011 Share Posted July 12, 2011 do you receive any errors upon uploading in your error.log? If, not, do you have your display_errors set to ON and error_reporting set to 1? If you are not sure, you can check with these lines... print(ini_get('display_errors')); print(ini_get('error_reporting')); error_reporting(E_ALL); if(!ini_get('display_errors')) {ini_set('display_errors','On')}; Quote Link to comment https://forums.phpfreaks.com/topic/241743-how-to-refer-to-the-uploaded-folder/#findComment-1241779 Share on other sites More sharing options...
upendra470 Posted July 13, 2011 Author Share Posted July 13, 2011 Thanx for the advice. But can you please tell me where i can find the error.log file? Quote Link to comment https://forums.phpfreaks.com/topic/241743-how-to-refer-to-the-uploaded-folder/#findComment-1242099 Share on other sites More sharing options...
upendra470 Posted July 13, 2011 Author Share Posted July 13, 2011 Warning: move_uploaded_file(upload/gallery/Image0081.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /home/gal37542/public_html/control/addgallery.php on line 48 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpzhEQW5' to 'upload/gallery/Image0081.jpg' in /home/gal37542/public_html/control/addgallery.php on line 48 I got these two warning while uploading the files. Can anyone tell my what i have to do to correct it. Any help will be appreciated. Thanx. Quote Link to comment https://forums.phpfreaks.com/topic/241743-how-to-refer-to-the-uploaded-folder/#findComment-1242108 Share on other sites More sharing options...
upendra470 Posted July 13, 2011 Author Share Posted July 13, 2011 The problem is solved now. I changed the permission of my uploaded folder to 0777 and added the full path to the move_uploaded_file function. Tha full path i gave /home/gal37542/public_html/control/upload/gallery/ And it worked fine!! Thank you to all of you! Quote Link to comment https://forums.phpfreaks.com/topic/241743-how-to-refer-to-the-uploaded-folder/#findComment-1242111 Share on other sites More sharing options...
AyKay47 Posted July 13, 2011 Share Posted July 13, 2011 There are better alternatives to changing directory permissions to 0777, which can be very dangerous. 1. you can make the directory using mkdir which will allow PHP access to the directory without having to change permissions. 2. You can use PHP's ftp functions to move the file into the specified web directory http://us3.php.net/manual/en/book.ftp.php Quote Link to comment https://forums.phpfreaks.com/topic/241743-how-to-refer-to-the-uploaded-folder/#findComment-1242190 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.