SitePoint Sponsor

User Tag List

Results 1 to 10 of 10

Thread: $_FILES & tmp

  1. #1
    SitePoint Guru augathra's Avatar
    Join Date
    Jul 2004
    Location
    united states
    Posts
    826
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    $_FILES & tmp

    Hello, if I upload all files as 'tmp_name', could any of them get overwritten?

  2. #2
    One website at a time mmj's Avatar
    Join Date
    Feb 2001
    Location
    Melbourne Australia
    Posts
    6,282
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    No, it is not possible to you to overwrite an existing file when you upload it. When uploaded, PHP gives it a unique temporary name of its own.
    [mmj] My magic jigsaw
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The Bit Depth Blog Twitter Contact me
    Neon Javascript Framework Jokes Android stuff

  3. #3
    SitePoint Guru augathra's Avatar
    Join Date
    Jul 2004
    Location
    united states
    Posts
    826
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks. I am planning on keeping the file names as their temporary names. Are there any bad effects of doing this?

  4. #4
    SitePoint Zealot shenkong's Avatar
    Join Date
    Sep 2004
    Location
    China
    Posts
    132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    don't use temporary names, try:
    PHP Code:
    $file $_FILES["file"];
    $name time() . rand() . $file["name"];
    move_uploaded_file($file["tmp_name"], "c:/"$name); 

  5. #5
    Are You There? KDesigns's Avatar
    Join Date
    Oct 2003
    Location
    Your Monitor
    Posts
    1,146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In some cases where there is a possibility of files having the same name I attach a datestamp to the end of the filename.
    ChooseDaily.com - Follow on Twitter
    Top Resources for Web Designers and Developers Every Day!

  6. #6
    Fully Sweet Car noddy's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Western Australia
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    How does the files permissions work from the tmp directory to the directory which you save it into also the permissions of the directory. Specially on a linux based machine?

  7. #7
    Are You There? KDesigns's Avatar
    Join Date
    Oct 2003
    Location
    Your Monitor
    Posts
    1,146
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Not sure about the tmp directory, but the way I do permissions on the directory that I upload the files to is:

    1) Use PHP to ftp to server CHMOD the directory to 777
    2) copy() the file to the directory
    3) Use PHP to CHMOD the directory to 755.
    ChooseDaily.com - Follow on Twitter
    Top Resources for Web Designers and Developers Every Day!

  8. #8
    One website at a time mmj's Avatar
    Join Date
    Feb 2001
    Location
    Melbourne Australia
    Posts
    6,282
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by noddy
    How does the files permissions work from the tmp directory to the directory which you save it into also the permissions of the directory. Specially on a linux based machine?
    You'll need to do some reading up on file permissions on a linux based machine. There's too much information to explain it well here. You'll also need to know which 'user' the web server is running as.

    Specifically, the web server user must have 'write' and 'execute' permission for the directory you're copying the file to (preferable 'read' as well, as you'll want to read that file later).

    Giving something a 777 (which means 'everybody has read, write and execute permission') is the easy way to do it, and you don't have to worry about owner/group. This may be suitable in some situations and unsuitable in others.
    [mmj] My magic jigsaw
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    The Bit Depth Blog Twitter Contact me
    Neon Javascript Framework Jokes Android stuff

  9. #9
    Fully Sweet Car noddy's Avatar
    Join Date
    Aug 2002
    Location
    Perth, Western Australia
    Posts
    759
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by mmj
    You'll need to do some reading up on file permissions on a linux based machine. There's too much information to explain it well here. You'll also need to know which 'user' the web server is running as.

    Specifically, the web server user must have 'write' and 'execute' permission for the directory you're copying the file to (preferable 'read' as well, as you'll want to read that file later).

    Giving something a 777 (which means 'everybody has read, write and execute permission') is the easy way to do it, and you don't have to worry about owner/group. This may be suitable in some situations and unsuitable in others.
    My photos file does have 777 but it still gets the webserver user group as its owner.

    So your says check out the permissions of the webserver user. ok will try that

  10. #10
    SitePoint Guru augathra's Avatar
    Join Date
    Jul 2004
    Location
    united states
    Posts
    826
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    shenkong, could you explain why i shouldn't?


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •