I am looking for some help on the following code I am working on. This code consist of a form in PHP to write entries inside the fields and take the fields entries and generate a CSV file on my server.
The problem is the file is not being generated on my server. I am not really a guru on PHP but I gotten so far that my php form is collecting the entries from the fields and making the filename csv which is good.
My code:
[php]if(isset($_POST[‘submit’])){
//collect form data
$location = $_POST['location'];
$ID = $_POST['ID'];
$section = $_POST['section'];
//check name is set
if($location ==''){
$error[] = 'Name is required';
}
//if no errors carry on
if(!isset($error)){
# Title of the CSV
$Content = "location, ID, section\n";
//set the data of the CSV
$Content .= "$location, $ID, $section\n";
# set the file name and create CSV file
$my_file = ("$location$ID$section.cvs");
$handle = fopen("$my_file", "w") or die('Cannot open file: '.$my_file);
header('Content-Type: application/csv');
header('Content-Disposition: attachment; filename="' . $FileName . '"');
echo $Content;
exit();
}
}
//if their are errors display them
if(isset($error)){
foreach($error as $error){
echo “
$error
”;}
}
?>
[/php]
After this my browser tells me:
Cannot open file: BOD10Buffer.cvs
So it cannot make open the csv and it wont create it on my server either.
I wanted to check if there might be anyone that could help me? Is there something I might be doing wrong? I know it’s not coded nicely and I apologize for this. Any help would be much appreciated.