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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.