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 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
    • By helmut2509
      Hello,
      I am just working on a multi-language pw app. Default language is german, then comes english.
      the language segment for english in the url is 'en-home' , eg. '../en-home/products', I think this was taken as a default option.
      (this happened several months ago, so I do not remember exactly...).
      Now I want to change this segment simply to 'en'. However, in 'Pages...Settings', only the part AFTER 'en-home' is editable, so I do not see any possibility
      to change this segment. Neither do the Languages Settings offer such a possibility ;-((
      Or do I miss something?
    • By zlitrox
      Hi!
      I'm relatively new to the world of Processwire, but so far I'm really impressed by this CMS and its ease, power and speed.
      I've been looking at the different field types and also existing CKEditor modules (pwimage and pwlink).
      Here's what i want to achieve:
      I would like to use or create a own module which allows my admin users to upload pdf files inline in a CKEditor field (page content) the same way images are handled. It should be possible to upload a pdf file and specify its name and from the file uploaded and name i want to show an icon or image inline in editor and the output for that upload should be customized based on the module. Lets make it simple and say that i upload datasheet-1.pdf and want it to be named "My product datasheet", i want the output to be:
      <a href="{ link to uploaded pdf file }">My product datasheet</a>  
      Also the uploaded pdf files should be related to the page the user is editing.
       
      Is this doable? 
       
      Any guidance would be greatly appreciated! Thanks in advance.
      PS. I'm a PHP programmer so i know it would require some custom code, but the real question is where do i start, what should it take and is it even possible to do?