Hi,
I'm relatively new to PHP, and have set myself a challenge to get something done.
I guess this isn't so much a question, but more me asking for advice really.. i.e., can it be done?!
I'm looking to do the following:
Stage 1:
- Create a form that allows me to upload a .csv file to a directory on my server [done]
- Create a script that reads the csv file during the upload, takes out a value from a specific line from within the .csv file (line 3 in this example) and use this variable as the value to rename the .csv file.
The form is complete, and allows me to upload a file into a directory.
I can read the name of the file using the following code:
$filename = basename( $_FILES['file']['name']);
..but can't for the life of me workout how to read a csv file, locate a specific string, and set this string as a variable to rename the file. Any ideas?
Stage 2:
Once the file is saved with it's new unique name, I need to read the data & style it (I already have a stylesheet set). I can read and render the data from the file using this code:
<?php
$row = 1;
$handle = fopen("report/mycsvfile.csv", "r");
while (($data = fgetcsv($handle, 1000, ",")) !== FALSE) {
$num = count($data);
echo "<p> $num fields in line $row: <br /></p>\n";
$row++;
for ($c=0; $c < $num; $c++) {
echo $data[$c] . "<br />\n";
}
}
fclose($handle);
?>
Is there a way to add styling to this using div id's / classes without needing to enter the data into the csv file first, or copy the rendered html into another file? (maybe I could save the html output and read that into another file.. not sure).
Stage 3:
Finally, once I've managed to read the data, rename the file & style the page, I would like to be able to save the page automatically into a PDF format. I've looked at a lot of pdf apps and a php pdf library also, but really need to be able to save a rendered page (with website branding and styled csv data) into the pdf. Does anybody know whether this is possible?
Not bad for my first post... a reasonably tall order i'm sure!
I guess once I know it's possible, it's just a case of research research research and a lot of hard work
hope to hear from you soon,
mic