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

Failed to open stream: No such file or directory #20

Open
CMeldgaard opened this issue Feb 13, 2023 · 6 comments
Open

Failed to open stream: No such file or directory #20

CMeldgaard opened this issue Feb 13, 2023 · 6 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@CMeldgaard
Copy link

The following line fails, if the public url of an assets doesn't match the server path. For instance if the public url ir /dowloads but the server path is /app/web/downloads it fails.

file_put_contents($tempPath, file_get_contents($asset->url));

My suggestion would be to use the path instead of the url

@bymayo
Copy link
Owner

bymayo commented Feb 14, 2023

@CMeldgaard Did you close this because it worked in the end or not?

I'm likely going to change this as path does work better, especially if the assets don't have a public URL's

@bymayo bymayo added bug Something isn't working enhancement New feature or request labels Feb 14, 2023
@bymayo bymayo reopened this Feb 14, 2023
@CMeldgaard
Copy link
Author

@bymayo i closed it as we found a solution based on an older issue. But yeah, filepath would be a good idea.

Perhaps a setting where you can switch between them, in case an external storage like S3 is used. That would give as much flexibility as possible for the developers implementing it :)

@useralberto
Copy link

Hello any news about this ? @bymayo

@fvwanja
Copy link

fvwanja commented Jan 15, 2025

Plugin version: 5.0.1
Craft Pro 5.5.9


Same here – I cannot use the plugin at all.

Screenshot 2025-01-15 at 14 04 11

Filetree:

├── bootstrap.php
├── composer.json
├── composer.lock
├── config
├── craft
├── frontend
├── storage
├── templates
├── translations
├── vendor
└── web
    ├── BaseStyle
    ├── assets
    ├── cpresources
    ├── favicon.ico
    ├── index.php
    ├── uploads 📝
    └── web.config

My files are at web/uploads. The can be accessed at http://example.local/uploads/file.pdf

The plugin is trying to interprete the path from the URL as the absolute file path.

A simple solution could be, that I can pass an absolute path to a file as a parameter instead of the Craft Asset. I could build the path easily in the config/general.php as an alias

    ->aliases([
        '@webroot' => dirname(__DIR__) . '/web', // resolves to directory /Users/foo/Documents/project-name/web

and use it in Twig:

{% set transformedPdf = craft.pdfTransform.render(alias('@webroot') ~ file.url) %}
{{ transformedPdf.one().url }}

@bymayo
Copy link
Owner

bymayo commented Jan 15, 2025

@fvwanja I need to change this to use path not URL in the plugin.

Can you just give me an example though of what your URL looks like and the path looks like? E.g.

https://website.com/uploads/whatever.pdf
/path/to/web/uploads/whatever.pdf

Just so I can see if this is any different

@fvwanja
Copy link

fvwanja commented Jan 16, 2025

Sure!

Domain: http://example.local

This is the relative path that the plugin tries to use from $asset->url:

/uploads/foo/bar/file.pdf

This is the actual absolute path:

/Users/xxx/Documents/projects/craft-xxx/web/uploads/foo/bar/file.pdf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants