Jump to content
gesp

image field changes file name

Recommended Posts

Hi there,

When I upload my files on the image field, it changes their name and uploads a file with a different name.

In this case I am building a Retina ready site and I really need these files t be uploaded as they are.

Their names end with '@2x', so 'file@2x.png' could be an example, but when I upload it, the file that appears on the assets/files/ folder is named 'file_2x.png'.

How can I control this?

Thanks

Share this post


Link to post
Share on other sites

I think that's the sanitizer at work. Can't think of a solution atm, but am sure somebody else will give you a better answer :)

Share this post


Link to post
Share on other sites

It doesn't really help you, but this is the culprit line:

https://github.com/ryancramerdesign/ProcessWire/blob/a8024bb49785370aa2e3867bd683094663cfeabf/wire/core/Pagefiles.php#L264

Ryan may consider adding @ to the list of allowed characters. I don't think there are any reasons why it needs to be removed.

I think historically it wasn't allowed in filenames, but now should be fine.

Some more reading:

http://en.wikipedia.org/wiki/Filename#Comparison%5Fof%5Ffile%5Fname%5Flimitations

http://superuser.com/questions/358855/what-characters-are-safe-in-cross-platform-file-names-for-linux-windows-and-os

Share this post


Link to post
Share on other sites

Indeed it should already permit the '@' usage. It should definitely be included on a future update, since it is having its own importance on retina support nowadays.

Thanks for the help guys ;)

(sorry for the long delay, but for some unknown reason I wasn't notified of your contributions, even though I have e-mail notifications on :P)

Share this post


Link to post
Share on other sites

You can create a repeater and allow users to upload a normal version of an image and a hd version. You won't need retina.js, however you'll need to pull out the hd detection and put it in a custom script that sets a session var or cookie or passes the variable to php via other methods json or ajax. 

<script>
// hd detection
// if hd enabled, set a cookie
</script>

Then when you loop through the repeater...

foreach ($images_repeater as $image) {
    if (($_COOKIE['hd'] === true) && ($image->hd_image)) {
        //show hd image
    } else {
        //show normal image
    }
}

You could also just upload the HD version and let PW create the normal sized image. 

foreach($page->images as $image) {
    $hd = $image->width(500); 
    $normal = $image->size(250);
    
    if ($_COOKIE['hd'] === true) {
        echo '<img src="{$hd->url}">';
    } else {
        echo '<img src="{$normal->url}">';
    }
}

Share this post


Link to post
Share on other sites

It doesn't really help you, but this is the culprit line:

https://github.com/ryancramerdesign/ProcessWire/blob/a8024bb49785370aa2e3867bd683094663cfeabf/wire/core/Pagefiles.php#L264

Ryan may consider adding @ to the list of allowed characters. I don't think there are any reasons why it needs to be removed.

I think historically it wasn't allowed in filenames, but now should be fine.

Some more reading:

http://en.wikipedia.org/wiki/Filename#Comparison%5Fof%5Ffile%5Fname%5Flimitations

http://superuser.com/questions/358855/what-characters-are-safe-in-cross-platform-file-names-for-linux-windows-and-os

I have tested this, replacing the line with:

$basename = preg_replace('/[^-_.a-zA-Z0-9@]/', '_', $basename); 
 

But it doesn't solve the problem and every image with a name ending in @2x.png will end up being uploaded as _2x.png

Any help?

Thanks

Share this post


Link to post
Share on other sites

There's a transliteration check box in the field config that rewrites the filename. If it's checked, that could be your problem.

Share this post


Link to post
Share on other sites

There's a transliteration check box in the field config that rewrites the filename. If it's checked, that could be your problem.

Where can I find this option? I checked the input field and found nothing related to this.

Share this post


Link to post
Share on other sites

Sorry, i was calling it by the wrong name. Details tab: Entity encode file description/tags?

Share this post


Link to post
Share on other sites

Sorry, i was calling it by the wrong name. Details tab: Entity encode file description/tags?

I have tried this with that option checked and unchecked. The result is the same, I upload the image and it changes from it's original name image@2x.png to image_2x.png

Any other solutions on this?

Share this post


Link to post
Share on other sites

Ok, I tracked down the problem.

You would need to also edit this line to allow @:

https://github.com/ryancramerdesign/ProcessWire/blob/master/wire/core/Upload.php#L200 (or "WireUpload.php if you are using the dev version)

If you do that along with the change I mentioned above in this line:

https://github.com/ryancramerdesign/ProcessWire/blob/a8024bb49785370aa2e3867bd683094663cfeabf/wire/core/Pagefiles.php#L264

it will let the @ go through.

Of course editing the core files is not recommended!

Share this post


Link to post
Share on other sites

I'm not exactly sure how those retina clients are testing for the existence of the @2x version, but if it's doing it by seeing if the request results in a 404 or not (which is what I'm assuming), then you should be able to accomplish this with an Apache rewrite rule in your .htaccess file:

RewriteRule ^(site/assets/files/[0-9]+/.+)@(2x\.[a-z]+)$ $1_$2

That would convert a request for /site/assets/files/123/filename@2x.jpg to /site/assets/files/filename_2x.jpg

  • Like 4

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Similar Content

    • By arnd
      Hi,
      I have a repeater with some images in it.
      As Superuser I can work with the Actions (rotate...). But my Users with lower Rights can't use this Actions.
      The same User can use the Actions on images outsite a Repeter-Field. So I think it's not a Problem of Rights-Management but from Images in Repeater Fields.
      ProcessWire 3.0.164.  Bug? Or can I manage this in the settings?
      Thanks in advance
    • By Mats
      BETA: SplashAndGrab
      https://github.com/madebymats/InputfieldSplashAndGrab
      This module attaches a search input to selected image fields that lets you search and download images from Unsplash.
      (Unsplash is a stock photo service where you can download images for free and use as you wish. No strings attached.)   
      You can search by string, colors, orientation/crop and order by relevance or time published
      I find Unsplash useful both for placeholder images when building sites but also as a time saver for editors if they don’t have any images at hand, just search, download and publish.

      Thanks to @apeisa for building the  FlickrInputField Module and @Robin S for AddImageUrls,  took a lot ideas and code from those modules.
    • By markus_blue_tomato
      We have created a module to create BlurHash strings for images while uploading in ProcessWire. This blurry images will be saved in the database because they are very small (20-30 characters) and can be used for Data-URL's  as placeholders for image-lazy loading.
      https://github.com/blue-tomato/ImageBlurhash
      E.g. where we use this in production:
      https://www.blue-tomato.com/en-INT/blue-world/ https://www.blue-tomato.com/en-INT/blue-world/products/girls-are-awesome/ https://www.blue-tomato.com/en-INT/buyers-guides/skateboard/skateboard-decks/ https://www.blue-tomato.com/en-INT/team/anna-gasser/
    • By Pip
      Hi, Everyone! 
      I'm currently working on a page reference field and set it for multiple pages (AsmSelect) for the input. Is there a way for me to add an image field (aka Avatar) and the title of page in the radio button? 
      I used the field name enclosed in the { }. Didn't work. It appeared a text instead. 
      Thanks in advance and hope to hear from you soon!
    • By EyeDentify
      Hello dear PW gurus.

      I have stumbled over a strange error that i all of sudden got when trying to upload an image to a images field on a page.
      There where images allready stored in the field that i wanted to keep, but during the upload the error apear and after that all images are gone from the field and i can´t upload any, i just get the error every time.
      I am running ProcessWire 3.0.153 dev.
      Update:
      After looking in the assets folder i find the folder for the page and the image files seems to be there including the ones i tried to upload when the error occured.
      But they don´t show up in the images field in the page editor.
       
      The error reported:
       
      SQLSTATE[01000]: Warning: 1265 Data truncated for column 'ratio' at row 1 And here is a screenshot of the event:

      The TracyDebugger Error reporting:

      I hope you fine folks could point me in a direction.
      But it seems our old pal set_time_limit() is back.

      Regards, EyeDentify
×
×
  • Create New...