Results 1 to 15 of 15

Thread: PHP File Upload

  1. #1

    Thread Starter
    Addicted Member TheGoldenShogun's Avatar
    Join Date
    Mar 2001
    Location
    VA/MD... anywhere around the beltway
    Posts
    236

    PHP File Upload

    Ok, I can manage to throw around a file thats already on a web server with PHP, but how do I get the program to that location on the webserver? Theres gotta be some php code to do that, right?

  2. #2

    Thread Starter
    Addicted Member TheGoldenShogun's Avatar
    Join Date
    Mar 2001
    Location
    VA/MD... anywhere around the beltway
    Posts
    236
    found it in the documentation, for anybody who needs to reference this, it worked fine for me.

    http://www.php.net/manual/en/features.file-upload.php

    heres how the code looked
    <?
    $uploaddir = "X:\\whateverdir;


    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir .".txt"))
    {
    print "File is valid, and was successfully uploaded!<br><br>";
    }
    else
    {
    print "Possible file upload attack! Here's some debugging info:<br><br>print_r($_FILES)";
    }

  3. #3
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    how can you throw around a file on the webserver if it is already there in php?

  4. #4
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    how can you throw around a file on the webserver if it is already there in php?
    What? You do realize that you're not making much sense these days...?
    My evil laugh has a squeak in it.

    kristopherwilson.com

  5. #5
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    yup, old age

    let me rephrase that

    how can you throw around a file on the webserver if it is already there, by using php?

  6. #6
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    yup, old age

    let me rephrase that

    how can you throw around a file on the webserver if it is already there, by using php?
    Haha, you're still not making sense to me. Maybe I don't understand the concept of 'throwing a file around.'

    I thought he just meant he could move a file around, but wanted to know how to get the file to the server in the first place.

    Color me confused, though.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  7. #7
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    hehe that was my impression.

    if the file is already there on the server how can he move it around using php? open it up and save it to another folder than delete the old one?

    as far as I know there isn't a function to do that. but I have been blind before

  8. #8

    Thread Starter
    Addicted Member TheGoldenShogun's Avatar
    Join Date
    Mar 2001
    Location
    VA/MD... anywhere around the beltway
    Posts
    236
    Sorry I haven't check this thread in awhile...

    basically The Hobo was right on. I know how to copy, move, delete, read from, etc etc, a file thats on my server but getting it to my server to play around with was the issue. Heres some file functions from php.net

    http://www.php.net/manual/en/function.copy.php

    actually thats just the copy function but all the other functions are listed along the left side. I love the way php.net list all the functions and handles documentation.

    Have fun.

  9. #9
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by TheGoldenShogun

    actually thats just the copy function but all the other functions are listed along the left side. I love the way php.net list all the functions and handles documentation.
    The downloadable .chm is even better
    My evil laugh has a squeak in it.

    kristopherwilson.com

  10. #10
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    Originally posted by TheGoldenShogun
    Sorry I haven't check this thread in awhile...

    basically The Hobo was right on. I know how to copy, move, delete, read from, etc etc, a file thats on my server but getting it to my server to play around with was the issue. Heres some file functions from php.net

    http://www.php.net/manual/en/function.copy.php

    actually thats just the copy function but all the other functions are listed along the left side. I love the way php.net list all the functions and handles documentation.

    Have fun.
    would you please explain to me how you move a file that is already on the server using php?

  11. #11
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    would you please explain to me how you move a file that is already on the server using php?
    Look up information on the copy() and unlink() file functions.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  12. #12

    Thread Starter
    Addicted Member TheGoldenShogun's Avatar
    Join Date
    Mar 2001
    Location
    VA/MD... anywhere around the beltway
    Posts
    236
    from my program, heres an example

    function copy_main_file()
    {
    copy("G:\\PROGRAMS\\UPLOADS\\uploaded_file.tmp", "G:\\PROGRAMS\\SYS\\".$date_name.".tmp");

    if (file_exists("G:\\PROGRAMS\\SYS\\".$date_name.".tmp"))
    {
    echo "Backup of the Uploaded file has been successfully saved..<br>";
    }
    }

  13. #13
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    well duh, I always thought copy was for uploads. just one of those things.

  14. #14
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by phpman
    well duh, I always thought copy was for uploads. just one of those things.
    I think there is a specific function for that, so you're not completely crazy.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  15. #15
    Frenzied Member
    Join Date
    Nov 1999
    Posts
    1,337
    well yeah, move_uploaded_file() but I don't like that one and always use copy()

Posting Permissions

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



Click Here to Expand Forum to Full Width