homma

How to upload files without changing original filenames

16 posts in this topic

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

1 person likes this

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

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 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?
    • By Dennis Spohr
      Hi all,
      in the backend of ProcessWire it's possible to define a maximum width and height for images. If you upload an image, it will be resized automatically. I find this feature very handy to safe space. Very often users upload images which are much bigger than needed.
      On my application users can upload their images via the frontend. But if you upload images using the API, images won't be resized automatically.
      Is there any way to do this?
      Currently that's my code:
      if ($_FILES['thumbnail']['name']) { $upload = new WireUpload('thumbnail'); $upload->setMaxFiles(1); $upload->setOverwrite(true); $upload->setDestinationPath($lesson->video_image->path()); $upload->setValidExtensions(array('jpg', 'jpeg', 'png')); $lesson->video_image->removeAll(); foreach ($upload->execute() as $file) $lesson->video_image->add($file); } Thanks very much!
      Dennis
    • By MilenKo
      Hello. Earlier I was able to implement a simple search on a knowledge sharing project for my company but now I was asked to add some functionality where to any page some files can be attached. It went pretty straight forward to use the FieldTypeFile and show up on the frontend all attached files by names.
      After completting the task I thougth that I could expand my search results allowing the query to search for a string within the attached file names and/or description. So on my working query:
      $matches = $pages->find("template!=keywords,title|body|keywords~=$q, limit=10");
      I tried adding the files_upload field which I created and assigned some file types. The final query got:
          $matches = $pages->find("template!=keywords,title|body|keywords|file_upload~=$q, limit=10");
      but I got a long error text:
      Error: Exception: SQLSTATE[HY000]: General error: 1191 Can't find FULLTEXT index matching the column list (in C:\OpenServer\domains\nowknow.pw\wire\core\PageFinder.php line 384)
      #0 [internal function]: ProcessWire\PageFinder->___find(Object(ProcessWire\Selectors), Array)
      #1 C:\OpenServer\domains\nowknow.pw\wire\core\Wire.php(374): call_user_func_array(Array, Array)
      #2 C:\OpenServer\domains\nowknow.pw\wire\core\WireHooks.php(549): ProcessWire\Wire->_callMethod('___find', Array)
      #3 C:\OpenServer\domains\nowknow.pw\wire\core\Wire.php(399): ProcessWire\WireHooks->runHooks(Object(ProcessWire\PageFinder), 'find', Array)
      #4 C:\OpenServer\domains\nowknow.pw\wire\core\PagesLoader.php(216): ProcessWire\Wire->__call('find', Array)
      #5 C:\OpenServer\domains\nowknow.pw\wire\core\PagesLoader.php(216): ProcessWire\PageFinder->find(Object(ProcessWire\Selectors), Array)
      #6 C:\OpenServer\domains\nowknow.pw\wire\core\Pages.php(225): ProcessWire\PagesLoader->find('template!=keywo...', Array)
      #7 [internal function]: ProcessWire\Pages->_
      This error message was shown because: site is in debug mode. ($config->debug = true; => /site/config.php). Error has been logged.
      Obviously I am not getting the correct way of searching for a file name or file description in the query. Any ideas how to accomplish that?
    • By joelplambeck
      Hey there,
      I'm very new to Processwire but allready in love!
      So far my experience was great but I ran into an internal server Error (500) and my error logfile logged:
      Error:     Exception: Unknown language (in P:\xampp\htdocs\xxx\wire\modules\LanguageSupport\Languages.php line 343)
      (I know XAMPP is not the best developing area but for simplicity reasons I like it...)
      The line 343 in my Languages.php(unchanged by me) is:
      if(!$language instanceof Language || !$language->id) throw new WireException("Unknown language"); in the function of 
      public function setLanguage($language) { if(is_int($language)) { $language = $this->get($language); } else if(is_string($language)) { $language = $this->get($this->wire('sanitizer')->pageNameUTF8($language)); } if(!$language instanceof Language || !$language->id) throw new WireException("Unknown language"); $user = $this->wire('user'); $this->savedLanguage2 = null; if($user->language && $user->language->id) { if($language->id == $user->language->id) return false; // no change necessary $this->savedLanguage2 = $user->language; } $user->language = $language; return true; } I have no clue what the problem is and as far as I know when I closed the website the day before everything was working just fine.
      I copied the whole folder to "develop" further on my laptop.
      The next day I got the error mentioned above when requesting the site. (On the original and the copy)
      Any suggestions what I should do?
    • By Peter Knight
      I was trying to fix an error earlier which was preventing a series of if statements from working.
      Basically I have a button called "Product Drawing" which needs localising depending on the current language session.
      Eventually got it working - I had a bracket in the wrong place.
       
      Curious as to why both these work though.
      On the sample below. each echo is surrounded by curly braces.
      <?php if ($page->files->count()) foreach($page->files->findTag('drawing') as $file) { if($user->language->name == 'default') {echo "<a href='$file->url' class='uk-button uk-button-primary'>Product drawing</a>";} if($user->language->name == 'french') {echo "<a href='$file->url' class='uk-button uk-button-primary'>Le plan du produit</a>";} if($user->language->name == 'german') {echo "<a href='$file->url' class='uk-button uk-button-primary'>Produktzeichnung</a>";} if($user->language->name == 'spanish') {echo "<a href='$file->url' class='uk-button uk-button-primary'>El dibujo del producto</a>";} if($user->language->name == 'italian') {echo "<a href='$file->url' class='uk-button uk-button-primary'>Il disegno del prodotto</a>";} } ?>  
      On the sample below, there are no curly braces around the echo
      <?php if ($page->files->count()) foreach($page->files->findTag('breakingreport') as $file) { if($user->language->name == 'default') echo "<a href='$file->url' class='uk-button uk-button-primary'>Breaking strain report</a>"; if($user->language->name == 'french') echo "<a href='$file->url' class='uk-button uk-button-primary'>Le test de rupture</a>"; if($user->language->name == 'german') echo "<a href='$file->url' class='uk-button uk-button-primary'>Bruchfestigkeit bericht</a>"; if($user->language->name == 'spanish') echo "<a href='$file->url' class='uk-button uk-button-primary'>Informe resistencia</a>"; if($user->language->name == 'italian') echo "<a href='$file->url' class='uk-button uk-button-primary'>La rottura rapporto ceppo</a>"; } ?>  
      Should the second piece work?