duplicating .csv

Hello!!!

I’m getting mad :frowning:

I have to write a script which has to open a .csv file from a folder and then copy the content, allow me to modificate it, and save it in the same folder (inside my project /var/www/…). So… the script has to open a .csv file, then the content has to be copied in another csv file and save this new file in the same folder where is the old one.

Any suggestion?
I was trying to create the new file with fopen and save it with fputcsv but it seems not working :frowning:

<?php $newfile = fopen("newfile.csv", 'w'); echo fgets($newfile); fclose($newfile); $fp = fopen ("csv-files/jardine.csv","r"); //open the file .csv while ($data = fgetcsv ($fp, 1000)) { //fgetcsv makes a lines between the pointer to a file and treat csv fields. Each line of the // .csv is saved in the array $data for after that, show data of the cells on screen. //print_r($data); fputcsv($fp, $data); echo "
".print_r($data,true).'
'; // tag pre preformatt the text } if (!copy($fp, $newfile)) { echo "failed to copy $fp...\n"; } fclose($newfile); fclose ( $fp ); // it closes the pointer ?>

Are you getting any errors?

Sponsor our Newsletter | Privacy Policy | Terms of Service