Trouble with chmod after upload

Discussion in 'PHP' started by petershaman, Oct 14, 2009.

  1. #1
    I'm using upload script, but after upload files are 600 instead 644, I tried put somewhere this bit of code:
    $chmod = chmod($path, 0766); //set the appropriate permissions.
    PHP:
    but i'm not sure where exactly it should be in this part of script's code pasted below:

    <?php
    /**
    * Menu-callback for JavaScript-based uploads.
    */
    function yui_editor_image_upload() {
      header("content-type: text/html"); // the return type must be text/html
      $response = null;
      $path = file_directory_path();
    
      //Append trailing slash to path if not there
      if (! (substr($path, -1) == '/')) {
        $path .= '/';
      }
      $path .= 'images';
      $file = file_save_upload('upload', array(), $path, FILE_EXISTS_REPLACE);
      if (!$file) {
        $response->status = 'Error Reading Uploaded File.';
        print drupal_to_js($response);
        exit;
      }
     
      $response->status = 'UPLOADED';
      $response->image_url = $file->filepath;
    
      print drupal_to_js($response);
      exit;
    }
    ?>
    PHP:

     
    petershaman, Oct 14, 2009 IP
  2. Kyosys

    Kyosys Peon

    Messages:
    226
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    0
    #2
    
    <?php
    /**
    * Menu-callback for JavaScript-based uploads.
    */
    function yui_editor_image_upload() {
      header("content-type: text/html"); // the return type must be text/html
      $response = null;
      $path = file_directory_path();
    
      //Append trailing slash to path if not there
      if (! (substr($path, -1) == '/')) {
        $path .= '/';
      }
      $path .= 'images';
      $file = file_save_upload('upload', array(), $path, FILE_EXISTS_REPLACE);
      if (!$file) {
        $response->status = 'Error Reading Uploaded File.';
        print drupal_to_js($response);
        exit;
      } else $chmod = chmod($file->filepath, 0766); //set the appropriate permissions. 
     
      $response->status = 'UPLOADED';
      $response->image_url = $file->filepath;
    
      print drupal_to_js($response);
      exit;
    }
    ?>
    Code (markup):
    $path will only change the directory chmod from the looks of it, so I changed it to $file->filepath
     
    Kyosys, Oct 14, 2009 IP
    petershaman likes this.
  3. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Just before this
    $response->status = 'UPLOADED';
     
    JAY6390, Oct 14, 2009 IP
  4. petershaman

    petershaman Peon

    Messages:
    12
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Thanks a lot, Kyosys ;-)
     
    petershaman, Oct 15, 2009 IP