Jump to content

Creating CSV and uploading to FTP site


dc_jt

Recommended Posts

Hi I am looking to create a csv file based on the data entered in a contact form and then upload this csv file to an FTP server.

 

I have created the CSV using the following code but unsure how to upload this to the FTP site (which is on another server) rather than my own site. Any idea?

 

$sDate=date('Y')."-".date('m')."-".date('d')."-".time();
    		
    		$filename = $sDate."_contact.csv";
                //path to uploads folder on my site
    		$filename_path = UPLOADS_PATH.'/csv_files/'.$filename;     

		//open the file for APPENDING
		//add the "t" terminator for windows
		//if using a mac then set the ini directive
		$fh = fopen($filename_path, "at");
		//Lock the file for the write operation
		flock($fh, LOCK_EX);

		$sType = "Contact Form Enquiry";

		$sName = explode(" ", $_POST[name]);
		$sForename = $sName[0];
		$sSurname = $sName[1];
		$top = 'Type,Forename,Surname,Company,Telephone,Email,Comment,Date Added,Notes';

		$top .="\n";

		$top .='"'.$sType.'",';
		$top .='"'.$sForename.'",';
		$top .='"'.$sSurname.'",';
		$top .='"'.$_POST[company].'",';
		$top .='"'.$_POST[telephone].'",';
		$top .='"'.$_POST[email].'",';
		$top .='"'.$_POST[comment].'",';
		$top .='"'.date('d')."/".date('m')."/".date('Y').'",';
		$top .='" ",';
		$top .="\n";

		fwrite($fh, $top ."\n",strlen($top));
		fclose($fh); 

Link to comment
https://forums.phpfreaks.com/topic/172103-creating-csv-and-uploading-to-ftp-site/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.