File upload problem, Chmod

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ian N

    File upload problem, Chmod

    Hi i'm having a problem with file permissions of upload, they appear to
    be being set to only readable by the administrator, so anyone browsing
    the site gets a 403 forbidden error when they try and view the image.

    I've tried adding the following line: -

    chmod($uploadfi le, 444);

    and also a few variations on it but to no avail.

    Could someone please point me in the right direction?

    Thanks in advance.

    Ian

    Script below: -

    if($_FILES['imageloc']['name'] == '') {
    echo 'The Small image remains the same or default<br />';
    }
    elseif($_FILES['imageloc']['size'] > $MAX_FILE_SIZE) {
    echo 'The small image you selected is too large<br />';
    }
    elseif(!getimag esize($_FILES['imageloc']['tmp_name'])) {
    echo 'The small image you selected is not a valid image file<br
    />';
    }
    else {
    $uploaddir = '/web/html/images/'; // remember the trailing slash!
    $uploadfile = $uploaddir. $_FILES['imageloc']['name'];
    chmod($uploadfi le, 444);
    if(move_uploade d_file($_FILES['imageloc']['tmp_name'],
    $uploadfile)) {

    echo 'Upload file success!';
    }
    else {
    echo 'There was a problem uploading your file.<br />';
    print_r($_FILES );
    }

  • CyberDog

    #2
    Re: File upload problem, Chmod

    Ian N wrote:[color=blue]
    > Hi i'm having a problem with file permissions of upload, they appear to
    > be being set to only readable by the administrator, so anyone browsing
    > the site gets a 403 forbidden error when they try and view the image.
    >
    > I've tried adding the following line: -
    >
    > chmod($uploadfi le, 444);[/color]

    You need to use the octal format,
    example: chmod($uploadfi le, 0444);

    and I think that 0755 would be more appropriate.

    Comment

    • Erwin Moller

      #3
      Re: File upload problem, Chmod

      Ian N wrote:
      [color=blue]
      > Hi i'm having a problem with file permissions of upload, they appear to
      > be being set to only readable by the administrator, so anyone browsing
      > the site gets a 403 forbidden error when they try and view the image.
      >
      > I've tried adding the following line: -
      >
      > chmod($uploadfi le, 444);
      >
      > and also a few variations on it but to no avail.
      >
      > Could someone please point me in the right direction?
      >
      > Thanks in advance.
      >
      > Ian
      >
      > Script below: -
      >
      > if($_FILES['imageloc']['name'] == '') {
      > echo 'The Small image remains the same or default<br />';
      > }
      > elseif($_FILES['imageloc']['size'] > $MAX_FILE_SIZE) {
      > echo 'The small image you selected is too large<br />';
      > }
      > elseif(!getimag esize($_FILES['imageloc']['tmp_name'])) {
      > echo 'The small image you selected is not a valid image file<br
      > />';
      > }
      > else {
      > $uploaddir = '/web/html/images/'; // remember the trailing slash!
      > $uploadfile = $uploaddir. $_FILES['imageloc']['name'];
      > chmod($uploadfi le, 444);
      > if(move_uploade d_file($_FILES['imageloc']['tmp_name'],
      > $uploadfile)) {
      >
      > echo 'Upload file success!';
      > }
      > else {
      > echo 'There was a problem uploading your file.<br />';
      > print_r($_FILES );
      > }[/color]


      Hi,

      Maybe it helps if you first move the file, then chmod it.
      Now you are trying to chmod the file while it is in the temp-directory.

      It has its TEMPname, not the filename

      So 2 solutions:

      1)
      $uploadfile = $uploaddir. $_FILES['imageloc']['tmp_name'];
      chmod($uploadfi le, 444);

      2) first move it to the path and name you like, then chmod it (with the
      right name).

      Regards,
      Erwin Moller

      Comment

      • Erwin Moller

        #4
        Re: File upload problem, Chmod

        Erwin Moller wrote:

        [color=blue]
        >
        > Hi,
        >
        > Maybe it helps if you first move the file, then chmod it.
        > Now you are trying to chmod the file while it is in the temp-directory.
        >
        > It has its TEMPname, not the filename
        >
        > So 2 solutions:
        >
        > 1)
        > $uploadfile = $uploaddir. $_FILES['imageloc']['tmp_name'];
        > chmod($uploadfi le, 444);
        >
        > 2) first move it to the path and name you like, then chmod it (with the
        > right name).
        >
        > Regards,
        > Erwin Moller[/color]

        Hi, I made a mistake, because it did misread your code.

        The solution is:
        1) first move the file to a new path/name
        Then chmod it.

        If you try to chmod it in the tmp-directory, you should use the tmp_name.

        Regards,
        Erwin Moller

        Comment

        • Ian N

          #5
          Re: File upload problem, Chmod

          Cheers!

          Got it sorted, thanks for your help

          Ian

          Comment

          Working...