Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
Added ability to create missing folders with saveToFile methods.
Browse files Browse the repository at this point in the history
  • Loading branch information
Burak Karakan committed Mar 2, 2017
1 parent 1d3a2ec commit 5bfee84
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/Reports/Report.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,10 @@ public function saveToFile($filePath) {
* @param $filePath
*/
public function downloadToFile($filePath) {

// Create the missing folders in the file path.
$this->createMissingFolders($filePath);

// Get the report object from AdWords.
$reportDownloadResult = $this->downloadReportFromAdWords($this->reportType);
$reportDownloadResult->saveToFile($filePath);
Expand Down Expand Up @@ -260,15 +264,17 @@ public function get() {
* @param $contents
*/
private function file_force_contents($filePath, $contents) {
$directories = explode('/', $filePath);
$this->createMissingFolders($filePath);
file_put_contents($filePath, $contents);
}

private function createMissingFolders($path) {
$directories = explode('/', $path);
$fileName = array_pop($directories);
$filePath = '';
foreach ($directories as $directory) {
if (!is_dir($filePath .= "/$directory")) {
mkdir($filePath);
}
$path = implode('/', $directories);
if (!is_dir($path)) {
mkdir($path, 0, true);
}
file_put_contents("$filePath/$fileName", $contents);
}

}

0 comments on commit 5bfee84

Please sign in to comment.