Jump to content

Recommended Posts

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";
}

?>

Link to comment
https://forums.phpfreaks.com/topic/241743-how-to-refer-to-the-uploaded-folder/
Share on other sites

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')};

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.

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!

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.