I want to create a CSV file from the SQL query results. Till now i have been using the local storage to store the file.
But now i want to open a ftp connection and open the file and write my chnages.
My code is as follow:
$ftp_server = "subdomain.domain.com";
$conn_id = ftp_connect($ftp_server) or die("Couldn't connect to $ftp_server");
$login_result = ftp_login($conn_id, 'uN@m3', '$pWd00');
$filename = 'ftp://uN@m3:$pWd00@subdomain.domain.com.com:21/db_user_export_'.time().'.csv'; //Change this to FTP URL of the server where File is going to be placed
function populateCSVforRightNowDatabase(){
global $database, $filename, $queryInterval, $logger;
/*My Query*/
if($resultSet->load()) {
// Create or Overwrite file
$handle = fopen($filename, 'w+');
// Write the spreadsheet column titles / labels
fputcsv($handle, array( /*columns*/));
foreach($resultSet as $result) {
fputcsv($handle, array(/*Results*/));
}
} else {
$message = "Load Error: " . $resultSet->getLoadError();
$logger->error($message);
}
// Finish writing the csv
fclose($handle);
}
fopensupports multiple read/write modes. However, the mode you selected,w+, is read/write mode, which is not supported by FTP. Barring other errors, usingworainstead should work.