SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Evangelist
    Join Date
    Mar 2011
    Location
    Bellingham, WA
    Posts
    450
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Disappearing download

    Hello!

    I'm trying to create a csv file, write it to my server, and then download it to a user's local computer. The first part of my code successfully creates the file:
    PHP Code:
    $fp fopen('filetest.csv''w') or die("can't open file"); //write to a file
    foreach ($list as $fields) {
        
    fputcsv($fp$fields);
    }
    fclose($fp); 
    At this point, I've looked on my server and found filetest.csv, safe and sound. However, if I continued to try and download it, running the full script:

    PHP Code:
    // define some variables
    $local_file 'filetest.csv';
    $server_file '/Instructors/filetest.csv';

    // set up basic connection
    $ftp_server "myalgebrabook.com"
    $conn_id ftp_connect($ftp_server);

    // login with username and password
    $ftp_user_name "mydatabase"
    $ftp_user_pass "fakepassword"

    $login_result ftp_login($conn_id$ftp_user_name$ftp_user_pass);

    // try to download $server_file and save to $local_file
    if (ftp_get($conn_id$local_file$server_fileFTP_BINARY)) {
        echo 
    "Successfully written to $local_file\n";
    } else {
        echo 
    "There was a problem\n";
    }

    // close the connection
    ftp_close($conn_id); 
    I get the following error: Can't open /Instructors/filetest.csv: No such file or directory in /home/myaglebr/public_html/Instructors/download_assignment_scores.php

    AND if I go back on the server, the filetest.csv disappears. In other words, just writing the file to the server works fine, but writing to the file and then trying to download somehow deletes the filetest.csv file, gives me the above error, and doesn't download anything.

    Any help would be appreciated.

    Thank you,

    Eric

  2. #2
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    71 Post(s)
    Tagged
    0 Thread(s)
    / is not what you think it is.
    The error message should give you a clue....

    I get the following error: Can't open /Instructors/filetest.csv: No such file or directory in /home/myaglebr/public_html/Instructors/download_assignment_scores.php

  3. #3
    SitePoint Evangelist
    Join Date
    Mar 2011
    Location
    Bellingham, WA
    Posts
    450
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thank you for replying to the post! I actually also tried "/home/myaglebr/public_html/Instructors/filetest.csv" (I think that this what you're getting at) but to no avail. Also, it would seem that it's finding the file, and acting on it --- from my original post, you can see that the file is deleted from the server without actually downloading it.

    Any other hints would be appreciated!

  4. #4
    SitePoint Enthusiast
    Join Date
    Aug 2010
    Location
    Perundurai, Tamilnadu, India
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If you are downloading it locally, then why don't use http and cURL to download it, i feel much more easier.

    yourwebsite.com/Instructors/filetest.csv

  5. #5
    Keeper of the SFL StarLion's Avatar
    Join Date
    Feb 2006
    Location
    Atlanta, GA, USA
    Posts
    3,748
    Mentioned
    71 Post(s)
    Tagged
    0 Thread(s)
    as tamil says, ftp cant do anything to a local computer (unless said computer has an FTP server on it). Output the file (echo file_get_contents) to the browser and give it the standard header for a download (Content-Disposition: attachment; filename="filenamegoeshere")

  6. #6
    SitePoint Evangelist
    Join Date
    Mar 2011
    Location
    Bellingham, WA
    Posts
    450
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thank you both. It's my first time downloading through PHP and with these tips I'm sure that I'll be able to make it happen.


    Cheers!


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
  •