Hi,
I am new to php and need help in :
1.Loop through a folder of files.
- Each filename is built up as: customerid_invoiceid.pdf
- Extract these id's
For example:files are stored in "c:/PDF/ customerid1_invoiceid1.pdf and so on
Can you please help me on how to do this using symfony?
need help in symfony project
Moderator: General Moderators
Re: need help in symfony project
What have you tried so far and where are you getting stuck?
- Christopher
- Site Administrator
- Posts: 13596
- Joined: Wed Aug 25, 2004 7:54 pm
- Location: New York, NY, US
Re: need help in symfony project
Yes, please any code you have tried? A list of files in a folder would be glob(). And string functions and explode() to get the IDs from the file names.
(#10850)
Re: need help in symfony project
Something like Flysystem could also be handy.
Re: need help in symfony project
<?php
$dir = 'C:/temp/invoice';
$files1 = scandir($dir,1);
$files2 = scandir($dir, 1);
$user = explode("_", $files1[0]);
print_r($user);
?>
How do I loop this?Also is there any better way to do this in symfony?
$dir = 'C:/temp/invoice';
$files1 = scandir($dir,1);
$files2 = scandir($dir, 1);
$user = explode("_", $files1[0]);
print_r($user);
?>
How do I loop this?Also is there any better way to do this in symfony?
Re: need help in symfony project
Code: Select all
protected function execute(InputInterface $input, OutputInterface $output)
{
$output->writeln("Begin!");
$finder = new Finder();
//$finder->files()->in($path);
$finder->files()->in('/home/invoice');
// $finder->in('invoice');
foreach ($finder as $file) {
$user=explode("_", $file->getRelativePathname());
}
$output->writeln("End");
}Re: need help in symfony project
Seems pretty good to me. I would recommend allowing the path to be a variable rather than hard coded, and I'd try to find a better name than execute(), but on the whole it seems fine. Is it not working?
Re: need help in symfony project
Yeah it is working...