Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for folders #12

Closed
wants to merge 2 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions src-php/Adapters/CloudinaryAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,19 @@ class CloudinaryAdapter extends CloudinaryBaseAdapter
*/
public function writeStream($path, $resource, Config $config)
{
$path = pathinfo($path)['filename'];
$pathinfo = pathinfo($path);
$folder = $pathinfo['dirname'];
$path = $pathinfo['filename'];

$options = ['public_id' => $path, 'resource_type' => 'auto'];

if ($folder != '.') {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does pathinfo always return a . for dirname if the file is in the cwd?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As far as I remember, yes

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at https://www.php.net/manual/en/function.dirname.php this could be a . / or \?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I was running it on mac (or Heroku) it was .. I don't have access to Windows machine to check what happens there

$options['folder'] = $folder;
}

$resource_metadata = stream_get_meta_data($resource);
$uploaded_metadata = Uploader::upload($resource_metadata['uri'], ['public_id' => $path, 'resource_type' => 'auto']);
$uploaded_metadata = Uploader::upload($resource_metadata['uri'], $options);

return $uploaded_metadata;
}

Expand Down