homma

How to upload files without changing original filenames

Recommended Posts

How can I upload files without changing the original filenames?

I use processwire in English and Japanese.
When I upload a file, the filename is sanitized and changed to an alphanumeric name.

I need some files to be uploaded with original filenames with Japanese characters (2-byte characters).

Is there a good way to do this?

Thanks in advance,

Yu

Share this post


Link to post
Share on other sites

Hi,

ProcessWire doesn't support non alpha numberic file name. I have made a feature request in within and waiting Ryan implement it but seems that he has no plan to do it in the near future. 

Gideon

Share this post


Link to post
Share on other sites

Hello Gideon,

Thanks for your message. It's a pity that non-alphanumeric filenames are not supported.
I need to integrate another file management system just because of this. Wordpress has a option to keep the original filenames, but I really want to use Processwire for my project.

@ryan, do you have any plan to implement this feature, in the core or plugin (or anything)?

Yu

Share this post


Link to post
Share on other sites
16 hours ago, homma said:

I need some files to be uploaded with original filenames with Japanese characters (2-byte characters).

may i ask WHY? if we know the reason we may can suggest some other way of achieving almost the same need ;)

Share this post


Link to post
Share on other sites

Hello all,

Thank you for your advice!

@bernhard, the reason is that I need to let users download files with Japanese filenames.
So, as @abdus suggested, if I can change the filename to, for example the value in 'Description' field of the file, it is OK.
I don't need to keep original filenames on the webserver.

Would you advice me how I can do this?

Thank you!
Yu

Share this post


Link to post
Share on other sites

you could just take the code example from abdus, activate url segments for your site and do something like this:

// list your files to download
foreach($page->files as $i=>$file) {
  echo '<a href="' . $page->url . $i . '" target="_blank">Download File ' . ($i+1) . '</a>';
}

and in your template file:

if($num = $input->urlSegment1) {
  $file = $page->files->eq($num);
  // continue with abdus script
}

maybe not without bugs but should show one possible solution :)

Share this post


Link to post
Share on other sites

Thank you @bernhard and @abdus !
The download attribute is very simple and easy, but I'm not sure I can ignore IE.


I'll work on this and come back with (hopefully good) results :)

Yu

Share this post


Link to post
Share on other sites

Hello @Gideon So and @adrian,

Thank you for sharing the github link. I quickly read the threads and noticed some people have the same concern.
I wanted to test the modified core file, but the Dropbox link seems to expire now. Do you happen to have a copy?

I currently try the solution bernhard and abdus suggested, but it turns out simply use Content-Disposition doesn't work on some browsers.
I'm looking at this code now, which partially solve my problem.
http://qiita.com/mpyw/items/202bef4349bfdc7e5c13#_reference-20f16504015c97498dc5 (article in Japanese)

Yu

Share this post


Link to post
Share on other sites
11 hours ago, homma said:

Hello @Gideon So and @adrian,

Thank you for sharing the github link. I quickly read the threads and noticed some people have the same concern.
I wanted to test the modified core file, but the Dropbox link seems to expire now. Do you happen to have a copy?

Yu

 

Hi @homma,

Yes. I do keep a copy here. It is for 3.0.42. I am not sure whether it works with the latest version.

Gideon

ProcessWireUploadDemo.zip

  • Like 1

Share this post


Link to post
Share on other sites
On 2017/8/13 at 11:18 AM, homma said:

Thank you @Gideon So!

I tested it and it worked quite well. I really hope this feature is realised in the core...

Yu

Hi @homma,

Glad that it works for you. Which version of ProcessWire you use?? 

Gideon

Share this post


Link to post
Share on other sites
2 hours ago, Gideon So said:

Hi @homma,

Glad that it works for you. Which version of ProcessWire you use?? 

Gideon

Hello @Gideon So,

I'm using PW 3.0.62 (stable).

Yu

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 SeoGuy
      Does anyone here have experience installing a translation module that creates new pages for multiple languages?
      I am assuming when these pages are generated, they are indexable by google as "new" and "fresh."
      Thoughts?
    • By jploch
      Hi!
      I have a problem with uploading animated GIFs again.
      The upload starts, but never finishes and just loads forever.
      Iam running PW 3.0.62 and have the Image Animated GIF Module installed.

      I also increased the memory limit in the htaccess file in PW root directory like this:
      <IfModule mod_php5.c>
      php_value memory_limit 256
      php_value upload_max_filesize 64M
      php_value post_max_size 64M
      php_value max_execution_time 300
      php_value max_input_time 1000
      </IfModule> 
      I had this problem before, but was able to fix it with the Animated GIF Module and the modification of the htaccess file.
      So maybe this is related to the provider (strato).
      Here is the error I get, when uploading the GIF (1.1 MB filesize)
      Warning: preg_match_all() expects at least 3 parameters, 2 given in /mnt/web216/a2/50/51925650/htdocs/processwire/wire/core/PWGIF.php on line 252 Warning: preg_match_all() expects at least 3 parameters, 2 given in /mnt/web216/a2/50/51925650/htdocs/processwire/site/assets/cache/FileCompiler/site/modules/ImageAnimatedGif/ImageAnimatedGif.module on line 285 Warning: preg_match_all() expects at least 3 parameters, 2 given in /mnt/web216/a2/50/51925650/htdocs/processwire/wire/core/PWGIF.php on line 252 Warning: preg_match_all() expects at least 3 parameters, 2 given in /mnt/web216/a2/50/51925650/htdocs/processwire/wire/core/PWGIF.php on line 252 Warning: preg_match_all() expects at least 3 parameters, 2 given in /mnt/web216/a2/50/51925650/htdocs/processwire/site/assets/cache/FileCompiler/site/modules/ImageAnimatedGif/ImageAnimatedGif.module on line 285 Warning: preg_match_all() expects at least 3 parameters, 2 given in /mnt/web216/a2/50/51925650/htdocs/processwire/wire/core/PWGIF.php on line 252 [{"error":false,"message":"Added file: test.gif","file":"\/processwire\/site\/assets\/files\/1098\/test.gif","size":101734,"markup":"<li id='file_daf280af792fd5b906511363ae2bc39d' class='ImageOuter gridImage ui-widget'><div class='gridImage__tooltip'><table><tr><th>Dimensions<\/th><td>500x333<\/td><\/tr><tr><th>Filesize<\/th><td>99&nbsp;kB<\/td><\/tr><tr><th>Variations<\/th><td>0<\/td><\/tr><\/table><\/div>\n\t\t\t<div class='gridImage__overflow'>\n\t\t\t\t<img src=\"\/processwire\/site\/assets\/files\/1098\/test.0x260.gif?nc=1509109293\" alt=\"\" data-w=\"500\" data-h=\"333\" data-original=\"\/processwire\/site\/assets\/files\/1098\/test.gif?nc=1509109293\" \/>\n\t\t\t<\/div>\n\t\t\t\n\t\t\t\t<div class='gridImage__hover'>\n\t\t\t\t\t<div class='gridImage__inner'>\n\t\t\t\t\t\t<label for='' class='gridImage__trash'>\n\t\t\t\t\t\t\t<input class='gridImage__deletebox' type='checkbox' name='delete_thumbnail_daf280af792fd5b906511363ae2bc39d' value='1' title='Delete' \/>\n\t\t\t\t\t\t\t<span class='fa fa-trash-o'><\/span>\n\t\t\t\t\t\t<\/label>\n\t\t\t\t\t\t<a class='gridImage__edit'>\n\t\t\t\t\t\t\t<span>Edit<\/span>\n\t\t\t\t\t\t<\/a>\n\t\t\t\t\t<\/div>\n\t\t\t\t<\/div>\n\t\t\t\n\t\t\t\t<div class='ImageData'>\n\t\t\t\t\t<h2 class='InputfieldImageEdit__name'><span contenteditable='true'>test<\/span>.gif<\/h2>\n\t\t\t\t\t<span class='InputfieldImageEdit__info'>99&nbsp;kB, 500&times;333 <\/span>\n\t\t\t\t\t<div class='InputfieldImageEdit__errors'><\/div>\n\t\t\t\t\t<div class='InputfieldImageEdit__buttons'><small><button type='button' data-href='\/processwire\/admin\/page\/image\/edit\/?id=1098&file=1098,test.gif&rte=0&field=thumbnail' class='InputfieldImageButtonCrop ui-button ui-corner-all ui-state-default pw-modal-large pw-modal' data-buttons='#non_rte_dialog_buttons button' data-autoclose='1' data-close='#non_rte_cancel'><span class='ui-button-text'><span class='fa fa-crop'><\/span> Crop<\/span><\/button><button type='button' data-href='\/processwire\/admin\/page\/image\/variations\/?id=1098&file=test.gif&modal=1&varcnt=varcnt_thumbnail_daf280af792fd5b906511363ae2bc39d' class='ui-button ui-corner-all ui-state-default pw-modal-large pw-modal' data-buttons='button'><span class='ui-button-text'><span class='fa fa-files-o'><\/span> Variations <span class='ui-priority-secondary'>(0)<\/span><\/span><\/button><\/small><\/div>\n\t\t\t\t\t<div class='InputfieldImageEdit__core'><div class='InputfieldFileDescription'><label for='description_thumbnail_daf280af792fd5b906511363ae2bc39d' class='detail'>Description<\/label><input type='text' name='description_thumbnail_daf280af792fd5b906511363ae2bc39d' id='description_thumbnail_daf280af792fd5b906511363ae2bc39d' value='' \/><\/div><\/div>\n\t\t\t\t\t<div class='InputfieldImageEdit__additional'><\/div>\n\t\t\t\t\t<input class='InputfieldFileSort' type='text' name='sort_thumbnail_daf280af792fd5b906511363ae2bc39d' value='1' \/>\n\t\t\t\t\t<input class='InputfieldFileReplace' type='hidden' name='replace_thumbnail_daf280af792fd5b906511363ae2bc39d' \/>\n\t\t\t\t\t<input class='InputfieldFileRename' type='hidden' name='rename_thumbnail_daf280af792fd5b906511363ae2bc39d' \/>\n\t\t\t\t<\/div>\n\t\t\t<\/li>","replace":true,"overwrite":0}]  
    • By louisstephens
      I have been looking up everything I can to try to find what's going wrong with this. I have a very simple form (title and file field set to multiple) that will create a new page with the name and attachments. However, it appears that I am missing something crucial as only 1 item gets uploaded to the field. Here is my code:
      <?php $uploadpage = new Page(); $uploadpage->template = "dashboard"; $uploadpage->parent = $pages->get("/testing/"); $uploadpage->title = $sanitizer->text($input->post->new_title); $uploadpage->save(); $uploadpage->setOutputFormatting(false); $u = new WireUpload('test_upload'); $u->setMaxFiles(6); $u->setOverwrite(false); $u->setDestinationPath($uploadpage->test_upload->path()); $u->setValidExtensions(array('jpg', 'jpeg', 'gif', 'png', 'pdf')); foreach($u->execute() as $filename) { $uploadpage->test_upload->add($filename); } $uploadpage->save(); ?> I have the max files set to 6, and have a foreach loop to add the files, but it is only uploading one. Does anyone see where I might have gone astray?
    • By franctic-aerobic
      Here's my Norwegian language pack for ProcessWire. I've been adding translations over some time, to suit my own projects users needs.
      Last updated:
      2017/10/02
      Status:
      Not yet complete. Translations that non-superusers will see is prioritized.
      Name:
      ProcessWire-Norwegian-Language-Pack-nb-NO
      Translated using:
      ProcessWire 3.0.77 dev
      Number of files:
      177 wire files and 68 site files – ranging from just started to completely translated. The site files includes translation some free and some pro modules, see the complete list in the README.md at GitHub.
      Available at Github:
      https://github.com/franctic-aerobic/ProcessWire-Norwegian-Language-Pack-nb-NO
    • By EyeDentify
      Simple example for loading template specific CSS file.
      This example asumes that you have your CSS file in a directory relative to template root.
      Like:
      templates/css/my_template_specific.css
      Also i use in the template a simple text field to hold the name of the CSS file i want to load.
      I call this field 'css_file'
      Use what you feel comfortable with.
      So in your header section of the DOM notice the "page specific CSS" part?
      Thats were the magic happens. What happens is that we check to see if the file exists in the CSS dir relative to template root.
      And if it does we load it. Simple and effective.
      I load all other CSS that is used all over the site in global_styles.css first.
      And make sure you load template specific last, because then you can easily override CSS in global.
       
      DOM header example:
      <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title><?PHP echo($page->title); ?></title> <!-- main CSS --> <link rel="stylesheet" href="<?PHP echo($config->urls->templates); ?>css/global_styles.css"> <!-- page specific CSS --> <?PHP /* Use relative path in file_exists() */ if(file_exists('css/' . $page->css_file)) { echo("<link rel=\"stylesheet\" href=\"{$config->urls->templates}css/{$page->css_file}\">"); } ?> </head> <body> Thats my way of doing it. I am sure there is plenty of more ways to do it. This is for the newbies or anyone that wants more options.
      Good luck with your CSS out there in Cyberspace.
      Cheers from EyeDentify