Ok well my problem is really weird, i'll try to explain it the best i can

Basically i have this image upload script ive been working a lot on, and with the help of some peoples... so i really dont want to start it over

My problem is that when an image is upload, i won't be able to touch the physical file.. I cannot download it from the ftp to my computer, i cannot change the chmod, but i can rename the file

BUT, i tryed it on a different server and everything works perfectly

Daniel0 suggested the problem was caused by this:

It's because your user nor your group hasn't got write access to the file. It's probably owned by whatever user and group your web server is running as. Only root is allowed to change the ownership using chown so you'll have to give write permissions to all.

BUT... The script is creating a thumbnail file of the uploaded file, and i have no problem with the thumb file!! I can transfer it, change the chmod, etc...

here is what some user of phpfreaks suggested:

Apache may save your upload as one user, then when you modify the original image to create a thumb, php may save as another user. So if you edit without resizing, your permissions will match.

So basically this is where i'm stuck at.... could anyone PLEASE help me to fix this script? I would be really happy if i can get this to work

    here is the script

    <?php
    include("db.php");
    $bbuserinfo['userid'] = "1";
    
    //This is the resize/sampler.
    function resample($img, $max_w, $max_h, $type, $thumb)
    {
    
    switch ($type) {
    
    case 2:
    
        // get original images width and height
        list($or_w, $or_h, $or_t) = getimagesize($img);
    
    
        // obtain the image's ratio
        $ratio = ($or_h / $or_w);
    
        // original image
        $or_image = imagecreatefromjpeg($img);
    
        // resize image?
        if ($or_w > $max_w || $or_h > $max_h) {
    
        // resize by height, then width (height dominant)
        if ($max_h < $max_w)
        {
    
        if ($or_h < $or_w)
        {
        $rs_w = $max_w;
        $rs_h = $rs_w * $ratio;
                }
    
        else
        {
        $rs_h = $max_h;
        $rs_w = $rs_h / $ratio;
        }
    
    
        }
    
        // resize by width, then height (width dominant)
        if ($max_w < $max_h)
        {
    
        if ($or_h < $or_w)
        {
        $rs_w = $max_w;
        $rs_h = $rs_w * $ratio;
        }
    
        else
        {
        $rs_h = $max_h;
        $rs_w = $rs_h / $ratio;
        }
    
    
        }
        //Resize by neither (as it is equal anyways)
        if ($max_w == $max_h)
        {
    
        if ($or_h < $or_w)
        {
        $rs_w = $max_w;
        $rs_h = $rs_w * $ratio;
        }
    
        else
        {
        $rs_h = $max_h;
        $rs_w = $rs_h / $ratio;
        }
    
        }
    
    
        // copy old image to new image
        $rs_image = @imagecreatetruecolor($rs_w, $rs_h);
        @imagecopyresampled($rs_image, $or_image, 0, 0, 0, 0, $rs_w, $rs_h, $or_w, $or_h);
        }
        // image requires no resizing
        else {
        $rs_w = $or_w;
        $rs_h = $or_h;
    
        $rs_image = $or_image;
        }
    
    
        if($thumb == true)
        {
            $image = explode('/',$img);
            $x = 0;
            $num_dir = count($image)-1;
            while($x < count($image)-1)
            {
            $pre_img .=$image[$x]."/";
            $x++;
            }
    
            $img = $pre_img."/sml_".$image[count($image)-1];
             $img;
        }
        // generate resized image
    
            imagejpeg($rs_image, $img, 100);
    
    
        return true;
    break;
    
    
    
    
    
    case 3:
    
    
        // get original images width and height
        list($or_w, $or_h, $or_t) = getimagesize($img);
    
    
        // obtain the image's ratio
        $ratio = ($or_h / $or_w);
    
        // original image
        $or_image = imagecreatefrompng($img);
    
        // resize image?
        if ($or_w > $max_w || $or_h > $max_h) {
    
        // resize by height, then width (height dominant)
        if ($max_h < $max_w)
        {
    
        if ($or_h < $or_w)
        {
        $rs_w = $max_w;
        $rs_h = $rs_w * $ratio;
                }
    
        else
        {
        $rs_h = $max_h;
        $rs_w = $rs_h / $ratio;
        }
    
    
        }
    
        // resize by width, then height (width dominant)
        if ($max_w < $max_h)
        {
    
        if ($or_h < $or_w)
        {
        $rs_w = $max_w;
        $rs_h = $rs_w * $ratio;
        }
    
        else
        {
        $rs_h = $max_h;
        $rs_w = $rs_h / $ratio;
        }
    
    
        }
        //Resize by neither (as it is equal anyways)
        if ($max_w == $max_h)
        {
    
        if ($or_h < $or_w)
        {
        $rs_w = $max_w;
        $rs_h = $rs_w * $ratio;
        }
    
        else
        {
        $rs_h = $max_h;
        $rs_w = $rs_h / $ratio;
        }
    
        }
    
    
        // copy old image to new image
        $rs_image = imagecreatetruecolor($rs_w, $rs_h);
        imagecopyresampled($rs_image, $or_image, 0, 0, 0, 0, $rs_w, $rs_h, $or_w, $or_h);
        }
        // image requires no resizing
        else {
        $rs_w = $or_w;
        $rs_h = $or_h;
    
        $rs_image = $or_image;
        }
    
        if($thumb == true)
        {
            $image = explode('/',$img);
            $img = $image[(count($image)-1)]."sml_".$image[count($image)];
            print $img;
        }
        // generate resized image
        imagepng($rs_image, $img, 100);
    
        return true;
       break;
    
    
    
    
    
    
    case 4:
    
    
        // get original images width and height
        list($or_w, $or_h, $or_t) = getimagesize($img);
    
    
        // obtain the image's ratio
        $ratio = ($or_h / $or_w);
    
        // original image
        $or_image = imagecreatefromgif($img);
    
        // resize image?
        if ($or_w > $max_w || $or_h > $max_h) {
    
        // resize by height, then width (height dominant)
        if ($max_h < $max_w)
        {
    
        if ($or_h < $or_w)
        {
        $rs_w = $max_w;
        $rs_h = $rs_w * $ratio;
                }
    
        else
        {
        $rs_h = $max_h;
        $rs_w = $rs_h / $ratio;
        }
    
    
        }
    
        // resize by width, then height (width dominant)
        if ($max_w < $max_h)
        {
    
        if ($or_h < $or_w)
        {
        $rs_w = $max_w;
        $rs_h = $rs_w * $ratio;
        }
    
        else
        {
        $rs_h = $max_h;
        $rs_w = $rs_h / $ratio;
        }
    
    
        }
        //Resize by neither (as it is equal anyways)
        if ($max_w == $max_h)
        {
    
        if ($or_h < $or_w)
        {
        $rs_w = $max_w;
        $rs_h = $rs_w * $ratio;
        }
    
        else
        {
        $rs_h = $max_h;
        $rs_w = $rs_h / $ratio;
        }
    
        }
    
    
        // copy old image to new image
        $rs_image = imagecreatetruecolor($rs_w, $rs_h);
        imagecopyresampled($rs_image, $or_image, 0, 0, 0, 0, $rs_w, $rs_h, $or_w, $or_h);
        }
        // image requires no resizing
        else {
        $rs_w = $or_w;
        $rs_h = $or_h;
    
        $rs_image = $or_image;
        }
    
        // generate resized image
        if($thumb == true)
        {
            $image = explode('/',$img);
            $img = $image[(count($image)-1)]."sml_".$image[count($image)];
            print $img;
        }
        imagegif($rs_image, $img, 100);
    
        return true;
       break;
    }
    
    }
    
    ?>
    
    
    
    
    
    
    
    
    <html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
    <head>
    <?php $headinclude;?>
    <title><?php $vboptions['bbtitle'];?></title>
    </head>
    <body>
    <br /><br /><br /><br />
    <center>
    
    <?php
    $bbuserinfo['userid'] = "1";
    if($bbuserinfo['userid'] != NULL)
    {}
    else
    {
    
    $url = 'connexion.php'; $timeout = 0;
    header('Refresh: ' . $timeout . ';url=' . $url);
    
    print'
    <meta http-equiv="refresh" content="'.$timeout.';url='.$url.';">
    
    <script type="text/javascript">
     setTimeout(function(){window.location.replace("'.$url.'; ", '.($timeout * 0).');
    </script>';
    
    }
    
    if($bbuserinfo['userid'])
    {
    print'
    
    <form action="'.$_server['php-self'].'" method="post"
    enctype="multipart/form-data" id="something" class="uniForm">
    ';
    
    // @include("imgbands.php"); //
    
    print'
    <br /><hr />
    <table>
    <tr>
    <td>
    Uploader la photo (#1):
    </td>
    <td>       
    <input name="new_image" id="new_image" size="30" type="file" class="fileUpload" /> </td> </tr> <tr> <td> Description (optionel): </td> <td> <INPUT TYPE="TEXT" NAME="infos" VALUE="" size="60"> </td> </tr> </table> <INPUT TYPE="hidden" NAME="user" VALUE="'.$bbuserinfo['username'].'" size="60"> <input name="submit" type="submit" class="submitButton" value="AJOUTER L\'IMAGE" /> </form> '; } $band = $_POST['band']; if($_POST['submit']) { $imagenamz = $_FILES['new_image']['name']; $originalname = $_FILES['new_image']['name']; $date = date('dmy'); $imagename = "$band" . "_" . $date . "_" . $originalname; echo $imagename; $vraidate = date('d/m/y'); $nom = $_POST['user']; $infos = $_POST['infos']; echo "<br />L'image a été ajouté dans l'album photos de <b>$band</b><hr><br />"; $source = $_FILES['new_image']['tmp_name']; $target = "db/img/images/".$imagename; move_uploaded_file($source, $target); $imagepath = $imagename; $save = "db/img/images/" . $imagepath; //This is the new fileyou saving $file = "db/img/images/" . $imagepath; //This is the originalfile list($width, $height, $att) = getimagesize($file) ; $size = getimagesize($file); $uploadx = $size[0]; $uploady = $size[1]; } list($width, $height, $type, $attr) = getimagesize($target); resample($target, 800, 800, $type, false); resample($target, 150, 150, $type, true); if(isset($_POST['submit'])){ // if file exists // add to database $filename = 'db/img/images/sml_".$imagepath."'; if (file_exists($filename)) { $band = $_POST['band']; $originalname = $_FILES['new_image']['name']; $date = date('dmy'); $imagename = "$band" . "_" . $date . "_" . $originalname; // echo $imagename; $vraidate = date('d/m/y'); $nom = $_POST['user']; $infos = $_POST['infos']; $result = mysql_query("INSERT INTO bands_pics (id,band,url,date,infos,valide,user) VALUES ('NULL', '$band', '$imagename','$vraidate','$infos','0','$nom')"); } } ?>

      here is the script

      <?php
      include("db.php");
      $bbuserinfo['userid'] = "1";
      
      //This is the resize/sampler.
      function resample($img, $max_w, $max_h, $type, $thumb)
      {
      
      switch ($type) {
      
      case 2:
      
          // get original images width and height
          list($or_w, $or_h, $or_t) = getimagesize($img);
      
      
          // obtain the image's ratio
          $ratio = ($or_h / $or_w);
      
          // original image
          $or_image = imagecreatefromjpeg($img);
      
          // resize image?
          if ($or_w > $max_w || $or_h > $max_h) {
      
          // resize by height, then width (height dominant)
          if ($max_h < $max_w)
          {
      
          if ($or_h < $or_w)
          {
          $rs_w = $max_w;
          $rs_h = $rs_w * $ratio;
                  }
      
          else
          {
          $rs_h = $max_h;
          $rs_w = $rs_h / $ratio;
          }
      
      
          }
      
          // resize by width, then height (width dominant)
          if ($max_w < $max_h)
          {
      
          if ($or_h < $or_w)
          {
          $rs_w = $max_w;
          $rs_h = $rs_w * $ratio;
          }
      
          else
          {
          $rs_h = $max_h;
          $rs_w = $rs_h / $ratio;
          }
      
      
          }
          //Resize by neither (as it is equal anyways)
          if ($max_w == $max_h)
          {
      
          if ($or_h < $or_w)
          {
          $rs_w = $max_w;
          $rs_h = $rs_w * $ratio;
          }
      
          else
          {
          $rs_h = $max_h;
          $rs_w = $rs_h / $ratio;
          }
      
          }
      
      
          // copy old image to new image
          $rs_image = @imagecreatetruecolor($rs_w, $rs_h);
          @imagecopyresampled($rs_image, $or_image, 0, 0, 0, 0, $rs_w, $rs_h, $or_w, $or_h);
          }
          // image requires no resizing
          else {
          $rs_w = $or_w;
          $rs_h = $or_h;
      
          $rs_image = $or_image;
          }
      
      
          if($thumb == true)
          {
              $image = explode('/',$img);
              $x = 0;
              $num_dir = count($image)-1;
              while($x < count($image)-1)
              {
              $pre_img .=$image[$x]."/";
              $x++;
              }
      
              $img = $pre_img."/sml_".$image[count($image)-1];
               $img;
          }
          // generate resized image
      
              imagejpeg($rs_image, $img, 100);
      
      
          return true;
      break;
      
      
      
      
      
      case 3:
      
      
          // get original images width and height
          list($or_w, $or_h, $or_t) = getimagesize($img);
      
      
          // obtain the image's ratio
          $ratio = ($or_h / $or_w);
      
          // original image
          $or_image = imagecreatefrompng($img);
      
          // resize image?
          if ($or_w > $max_w || $or_h > $max_h) {
      
          // resize by height, then width (height dominant)
          if ($max_h < $max_w)
          {
      
          if ($or_h < $or_w)
          {
          $rs_w = $max_w;
          $rs_h = $rs_w * $ratio;
                  }
      
          else
          {
          $rs_h = $max_h;
          $rs_w = $rs_h / $ratio;
          }
      
      
          }
      
          // resize by width, then height (width dominant)
          if ($max_w < $max_h)
          {
      
          if ($or_h < $or_w)
          {
          $rs_w = $max_w;
          $rs_h = $rs_w * $ratio;
          }
      
          else
          {
          $rs_h = $max_h;
          $rs_w = $rs_h / $ratio;
          }
      
      
          }
          //Resize by neither (as it is equal anyways)
          if ($max_w == $max_h)
          {
      
          if ($or_h < $or_w)
          {
          $rs_w = $max_w;
          $rs_h = $rs_w * $ratio;
          }
      
          else
          {
          $rs_h = $max_h;
          $rs_w = $rs_h / $ratio;
          }
      
          }
      
      
          // copy old image to new image
          $rs_image = imagecreatetruecolor($rs_w, $rs_h);
          imagecopyresampled($rs_image, $or_image, 0, 0, 0, 0, $rs_w, $rs_h, $or_w, $or_h);
          }
          // image requires no resizing
          else {
          $rs_w = $or_w;
          $rs_h = $or_h;
      
          $rs_image = $or_image;
          }
      
          if($thumb == true)
          {
              $image = explode('/',$img);
              $img = $image[(count($image)-1)]."sml_".$image[count($image)];
              print $img;
          }
          // generate resized image
          imagepng($rs_image, $img, 100);
      
          return true;
         break;
      
      
      
      
      
      
      case 4:
      
      
          // get original images width and height
          list($or_w, $or_h, $or_t) = getimagesize($img);
      
      
          // obtain the image's ratio
          $ratio = ($or_h / $or_w);
      
          // original image
          $or_image = imagecreatefromgif($img);
      
          // resize image?
          if ($or_w > $max_w || $or_h > $max_h) {
      
          // resize by height, then width (height dominant)
          if ($max_h < $max_w)
          {
      
          if ($or_h < $or_w)
          {
          $rs_w = $max_w;
          $rs_h = $rs_w * $ratio;
                  }
      
          else
          {
          $rs_h = $max_h;
          $rs_w = $rs_h / $ratio;
          }
      
      
          }
      
          // resize by width, then height (width dominant)
          if ($max_w < $max_h)
          {
      
          if ($or_h < $or_w)
          {
          $rs_w = $max_w;
          $rs_h = $rs_w * $ratio;
          }
      
          else
          {
          $rs_h = $max_h;
          $rs_w = $rs_h / $ratio;
          }
      
      
          }
          //Resize by neither (as it is equal anyways)
          if ($max_w == $max_h)
          {
      
          if ($or_h < $or_w)
          {
          $rs_w = $max_w;
          $rs_h = $rs_w * $ratio;
          }
      
          else
          {
          $rs_h = $max_h;
          $rs_w = $rs_h / $ratio;
          }
      
          }
      
      
          // copy old image to new image
          $rs_image = imagecreatetruecolor($rs_w, $rs_h);
          imagecopyresampled($rs_image, $or_image, 0, 0, 0, 0, $rs_w, $rs_h, $or_w, $or_h);
          }
          // image requires no resizing
          else {
          $rs_w = $or_w;
          $rs_h = $or_h;
      
          $rs_image = $or_image;
          }
      
          // generate resized image
          if($thumb == true)
          {
              $image = explode('/',$img);
              $img = $image[(count($image)-1)]."sml_".$image[count($image)];
              print $img;
          }
          imagegif($rs_image, $img, 100);
      
          return true;
         break;
      }
      
      }
      
      ?>
      
      
      
      
      
      
      
      
      <html dir="$stylevar[textdirection]" lang="$stylevar[languagecode]">
      <head>
      <?php $headinclude;?>
      <title><?php $vboptions['bbtitle'];?></title>
      </head>
      <body>
      <br /><br /><br /><br />
      <center>
      
      <?php
      $bbuserinfo['userid'] = "1";
      if($bbuserinfo['userid'] != NULL)
      {}
      else
      {
      
      $url = 'connexion.php'; $timeout = 0;
      header('Refresh: ' . $timeout . ';url=' . $url);
      
      print'
      <meta http-equiv="refresh" content="'.$timeout.';url='.$url.';">
      
      <script type="text/javascript">
       setTimeout(function(){window.location.replace("'.$url.'; ", '.($timeout * 0).');
      </script>';
      
      }
      
      if($bbuserinfo['userid'])
      {
      print'
      
      <form action="'.$_server['php-self'].'" method="post"
      enctype="multipart/form-data" id="something" class="uniForm">
      ';
      
      // @include("imgbands.php"); //
      
      print'
      <br /><hr />
      <table>
      <tr>
      <td>
      Uploader la photo (#1):
      </td>
      <td>       
      <input name="new_image" id="new_image" size="30" type="file" class="fileUpload" /> </td> </tr> <tr> <td> Description (optionel): </td> <td> <INPUT TYPE="TEXT" NAME="infos" VALUE="" size="60"> </td> </tr> </table> <INPUT TYPE="hidden" NAME="user" VALUE="'.$bbuserinfo['username'].'" size="60"> <input name="submit" type="submit" class="submitButton" value="AJOUTER L\'IMAGE" /> </form> '; } $band = $_POST['band']; if($_POST['submit']) { $imagenamz = $_FILES['new_image']['name']; $originalname = $_FILES['new_image']['name']; $date = date('dmy'); $imagename = "$band" . "_" . $date . "_" . $originalname; echo $imagename; $vraidate = date('d/m/y'); $nom = $_POST['user']; $infos = $_POST['infos']; echo "<br />L'image a été ajouté dans l'album photos de <b>$band</b><hr><br />"; $source = $_FILES['new_image']['tmp_name']; $target = "db/img/images/".$imagename; move_uploaded_file($source, $target); $imagepath = $imagename; $save = "db/img/images/" . $imagepath; //This is the new fileyou saving $file = "db/img/images/" . $imagepath; //This is the originalfile list($width, $height, $att) = getimagesize($file) ; $size = getimagesize($file); $uploadx = $size[0]; $uploady = $size[1]; } list($width, $height, $type, $attr) = getimagesize($target); resample($target, 800, 800, $type, false); resample($target, 150, 150, $type, true); if(isset($_POST['submit'])){ // if file exists // add to database $filename = 'db/img/images/sml_".$imagepath."'; if (file_exists($filename)) { $band = $_POST['band']; $originalname = $_FILES['new_image']['name']; $date = date('dmy'); $imagename = "$band" . "_" . $date . "_" . $originalname; // echo $imagename; $vraidate = date('d/m/y'); $nom = $_POST['user']; $infos = $_POST['infos']; $result = mysql_query("INSERT INTO bands_pics (id,band,url,date,infos,valide,user) VALUES ('NULL', '$band', '$imagename','$vraidate','$infos','0','$nom')"); } } ?>

        with all the lindes of code you have smeared over the thread, it is hard to tell where the actual upload occurs..

        If you do not have one: You should have a look at [man]move_uploaded_file[/man] which basically moves the file that was uploaded by the server (And has probably got server permissions) into your webspace, which should modify it into your permissions too.

        Basically th upload occurs to a temp folder on the server, and then you move the uploaded file to its final resting grounds.

          like i said, if i use the exact same script on a different server there is no problem at all. I can upload any images and i dont even have to change the chmod of anything

          and the file is correctly moved to the folder it is supposed to be in. If i look in my ftp, the file is already here...

          i'm not too sure if i understand what you are suggesting... could you give me an example with my code?

            First of all, please don't "bump" threads - there are a lot of questions being asked here, and everyone else's is just as important - or unimportant - as yours. We help people for free, so don't expect us to jump on your question because you say it's "desesperate" or urgent.

            Secondly, I'd guess the problem here is that your configurations are different from host to host - one host has file uploads configured a bit more loosely than the first, so the script works there but not on the other.

            Maybe try <?PHP echo phpinfo(); ?> on each host and compare the settings, or if you have access to the php.ini, look through that.

              Write a Reply...