Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Sep 2002
    Location
    Scotland
    Posts
    407
    Thanks
    0
    Thanked 0 Times in 0 Posts

    PHP file upload on windows server

    I have a simple PHP file upload script that works fine on my UNIX server but when I try to run it on a windows server I get the following error message:

    Warning: copy(D:\Inetpub\fsstrath\Live\upl\uploads) [function.copy]: failed to open stream: Permission denied in D:\Inetpub\fsstrath\Live\html\adm_fupload.php on line 6

    IIS permissions for the directory are set.

    I did a guick google and found out that for windows the path needs to be defined with double slashes - i.e D:\\Inetpub\\fsstrath\\Live\\upl\\uploads - but that didnt work.

    Any ideas/suggestions on whats causing this?
    My body's a temple... and like those ancient Greek ones it's a ruin
    sweenster.co.uk

  • #2
    Regular Coder
    Join Date
    Jan 2005
    Posts
    221
    Thanks
    2
    Thanked 0 Times in 0 Posts
    i thought it was only double slashes after the drive

    i.e.

    c://folder/file.ext


    but im not sure, never really used win server

  • #3
    Regular Coder
    Join Date
    Sep 2002
    Location
    Scotland
    Posts
    407
    Thanks
    0
    Thanked 0 Times in 0 Posts
    its ok... managed to figure it out. I stoped using copy and found a new function - move_uploaded_file:
    PHP Code:

    if(is_uploaded_file($_FILES['form_image']['tmp_name']))
    {
      
    // file uploaded to server
    move_uploaded_file($_FILES['form_image']['tmp_name'], "D:\\Inetpub\\fsstrath\\Live\\upl\\uploads\\".$_FILES['form_image']['name']);

        print (
    '<p class="bl"><strong>File is valid, and was successfully uploaded</strong></p>');
        print (
    '<p>Link to the file at:<br/><a href="upl/uploads/'.$_FILES['form_image']['name'].'" target ="_blank">upl/uploads/'.$_FILES['form_image']['name'].'</a></p>');
        print(
    '<p><a href="_indax.php?page=fupload&data='.$data.'&cat=0">Upload Another File</a></p>');
    }
    else
    {
        print (
    '<p class="bl"><strong>Unable to upload file.</strong></p><p>');
        
    print_r($_FILES);
        print(
    '</p>');

    My body's a temple... and like those ancient Greek ones it's a ruin
    sweenster.co.uk

  • #4
    Regular Coder
    Join Date
    Feb 2005
    Location
    West Midlands, UK
    Posts
    623
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yep, move_uploaded_file() is always a better option than copy(), since it's both open_basedir and safe_mode friendly the only thing you ever have to worry about is setting permissions on the directory you want to move the file to.


  •  

    Posting Permissions

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