upload script creating files with CHMOD 600

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • hadge
    New Member
    • Feb 2007
    • 5

    upload script creating files with CHMOD 600

    Hi im trying to get images to upload into a directory on my server but i cannot get them to upload as chmod 755 so that they are viewable can anyone help?

    [PHP]<?php include"connftp .php"; ?>

    <? if (($_FILES["file"]["type"] == "image/gif")
    || ($_FILES["file"]["type"] == "image/jpeg")
    && ($_FILES["file"]["size"] < 100000))
    {
    if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
    else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("u pload/" . $_FILES["file"]["name"]))
    {
    echo $_FILES["file"]["name"] . " already exists. ";
    }
    else
    {
    move_uploaded_f ile($_FILES["file"]["tmp_name"],
    "../upload/" . $_FILES["file"]["name"]);
    echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
    }
    }
    }
    else
    {
    echo "Invalid file";
    }
    ?>[/PHP]
  • xwero
    New Member
    • Feb 2007
    • 99

    #2
    after you move the file you can use chmod.

    [PHP]chmod('path/to/file/filename.ext',0 755);[/PHP]

    Comment

    • xwero
      New Member
      • Feb 2007
      • 99

      #3
      Originally posted by hadge

      [PHP]

      <? if (($_FILES["file"]["type"] == "image/gif")
      || ($_FILES["file"]["type"] == "image/jpeg")
      && ($_FILES["file"]["size"] < 100000))

      ?>[/PHP]
      if you only need to upload images it's best to check with getimagesize this gives you php fetched mime type instead of the browser fetched mime type which can not always be trusted. Contrary to it's name it doesn't get the file size.

      [PHP]

      <?
      $imagesize = getimagesize($_ FILES["file"]);
      if (($imagesize['mime'] == "image/gif")
      || ($imagesize['mime'] == "image/jpeg")
      || ($imagesize['mime'] == "image/pjpeg") // don't forget the IE mime type
      && ($_FILES["file"]["size"] < 100000))

      ?>[/PHP]

      Comment

      • hadge
        New Member
        • Feb 2007
        • 5

        #4
        Originally posted by xwero
        if you only need to upload images it's best to check with getimagesize this gives you php fetched mime type instead of the browser fetched mime type which can not always be trusted. Contrary to it's name it doesn't get the file size.

        [PHP]

        <?
        $imagesize = getimagesize($_ FILES["file"]);
        if (($imagesize['mime'] == "image/gif")
        || ($imagesize['mime'] == "image/jpeg")
        || ($imagesize['mime'] == "image/pjpeg") // don't forget the IE mime type
        && ($_FILES["file"]["size"] < 100000))

        ?>[/PHP]
        I can use the CHMOD script, but only to write individual file names, so if i use that i need to be able encompass the file name that is being uploaded into the script. ie
        "/www/var/html/"$_files
        But i havent been able to get it working :( with the embedded string

        Comment

        • xwero
          New Member
          • Feb 2007
          • 99

          #5
          Do you mean you want to upload multiple files?

          Comment

          • hadge
            New Member
            • Feb 2007
            • 5

            #6
            Originally posted by xwero
            Do you mean you want to upload multiple files?

            No i can specify the file (but i have to know what its called) meaning i will need to run CHMOD after the upload.

            But what i want it to do is chmod it as its being uploaded (so using the string for the file name)

            Comment

            • xwero
              New Member
              • Feb 2007
              • 99

              #7
              It's not possible to set the chmod during the upload because php uploads the file to a temporary file.

              Comment

              • hadge
                New Member
                • Feb 2007
                • 5

                #8
                Originally posted by xwero
                It's not possible to set the chmod during the upload because php uploads the file to a temporary file.
                Thanks Xwero

                Comment

                Working...