Page 1 of 2 12 Last
  • Jump to page:
    #1
  1. No Profile Picture
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    Newfoundland, Canada
    Posts
    30
    Rep Power
    13

    File uploads or FTP --- mental block


    Hello, here's my situation:
    User fills out a bunch of form fields, browses local HD and select a file then submits it.

    I want to upload that file to the webserver, with the results of the form inserted into the beginning of the file (just plain text, before the rest of the file from users HD)

    I can upload the file to the server and open the temporary file (form post result) --- this is not my problem. I cannot move or copy uploaded file from the temp space to my desired directory because of "permission denied". BTW I am using php on IIS.....

    How can I upload this file via PHP or FTP with a little bit of info prepended to it?

    Anyone have any suggestions? My explanation of the scenario suck and want to know more? Post here.

    Thanks All
    Steve
    Last edited by steveup; October 15th, 2002 at 10:11 PM.
  2. #2
  3. No Profile Picture
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    Newfoundland, Canada
    Posts
    30
    Rep Power
    13
    http://www.php.net/manual/en/function.fopen.php


    This is my best bet using the FTP option -- it looks like it may save me, although it seems when I open a new file for writing on the server, it is not created.....

    Thanks.

    Steve
    Last edited by steveup; October 16th, 2002 at 12:21 PM.
  4. #3
  5. Mobbing Gangster
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Sep 2001
    Location
    "Best City" 2002 and 2003- Melbourne, Australia
    Posts
    4,912
    Rep Power
    33
    >>I cannot move or copy uploaded file from the temp space to my desired directory
    On your http server or on remote ftp server?

    Generally what you need to do is first get file from user using http upload, then get your info from form into a var, open blank file, write that var in there, open uploaded file, read text from there and put it in new file then upload new file in ascii mode and delete both files at the end.
    And you know I mean that.
  6. #4
  7. PHP Programmer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Posts
    45
    Rep Power
    13
    if safe_mode is on in php.ini(not sure if this is where it is, but I would assume it is there), you need to use move_uploaded_file() instead of copy()
    //Adman
  8. #5
  9. No Profile Picture
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2002
    Location
    Newfoundland, Canada
    Posts
    30
    Rep Power
    13
    What you are saying makes sense and is how I planned to do it, but how do I open this blank temp file? Opening (touching) one remotely isnt an option - can I make a "pretend" temp file locally, which would be a result of the form and the userfile somehow, then upload that using ftp? Or maybe sleep is what I need.....

    Thanks

    Steve
  10. #6
  11. PHP Programmer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Posts
    45
    Rep Power
    13
    ftp should not be needed.
    //Adman
  12. #7
  13. Mobbing Gangster
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Sep 2001
    Location
    "Best City" 2002 and 2003- Melbourne, Australia
    Posts
    4,912
    Rep Power
    33
    Hold up, here's what I gathered from original post - steveup wants users to upload ascii file from their hdd to his server, put some info from form in the beginning of file (may be name/date?) and then upload it to remote ftp server for storage or public access. How far am I off on this one?
    And you know I mean that.
  14. #8
  15. PHP Programmer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Posts
    45
    Rep Power
    13
    PHP Code:
    $fp fopen($HTTP_POST_FILES['forminputname']['tmp_name'], "w+");
    $Contents fread($fpfilesize($HTTP_POST_FILES['forminputname']['tmp_name']);
    frwrite($fp$WhatToAdd.$Contents); 
    Just a shot in the dark.
    //Adman
  16. #9
  17. Mobbing Gangster
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Sep 2001
    Location
    "Best City" 2002 and 2003- Melbourne, Australia
    Posts
    4,912
    Rep Power
    33
    Good logic, adman, but flaw in the code. w+ erases all the content as soon as file is opened.
    And you know I mean that.
  18. #10
  19. PHP Programmer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Posts
    45
    Rep Power
    13
    then you would open if for appending instead.
    //Adman
  20. #11
  21. Mobbing Gangster
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Sep 2001
    Location
    "Best City" 2002 and 2003- Melbourne, Australia
    Posts
    4,912
    Rep Power
    33
    >>then you would open if for appending instead.
    ...which means adding info to the end rather then beginning, and we don't want that.

    steveup, could your describe what you want to do one more time?
    And you know I mean that.
  22. #12
  23. PHP Programmer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Posts
    45
    Rep Power
    13
    PHP Code:
    $fp fopen($HTTP_POST_FILES['forminputname']['tmp_name'], "r");
    $Contents fread($fpfilesize($HTTP_POST_FILES['forminputname']['tmp_name']);
    flcose($fp);

    $fp fopen($HTTP_POST_FILES['forminputname']['tmp_name'], "w");
    fwrite($fp$WhatToAdd.$Contents);
    fclose($fp); 
    How does that look Al
    Last edited by Adman; October 15th, 2002 at 11:16 PM.
    //Adman
  24. #13
  25. Mobbing Gangster
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Sep 2001
    Location
    "Best City" 2002 and 2003- Melbourne, Australia
    Posts
    4,912
    Rep Power
    33
    almost there - other then the fact you're opening it for reading both times and missing =
    And you know I mean that.
  26. #14
  27. PHP Programmer
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2002
    Posts
    45
    Rep Power
    13
    Edited
    //Adman
  28. #15
  29. Mobbing Gangster
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Sep 2001
    Location
    "Best City" 2002 and 2003- Melbourne, Australia
    Posts
    4,912
    Rep Power
    33
    I don't think he wants to keep that file in /tmp, so why don't you make it read from tmp_name but write to /home/whatever
    And you know I mean that.
Page 1 of 2 12 Last
  • Jump to page:

IMN logo majestic logo threadwatch logo seochat tools logo