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:
$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:
// 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_file, FTP_BINARY)) {
echo "Successfully written to $local_file\
";
} else {
echo "There was a problem\
";
}
// 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