samedi 2 janvier 2016

downloading files with unicode characters in their names in php

I use laravel5 and windows7 for my web developing.I have some links in my views that after clicking on those users can download their desired files.

<div class="col-xs-12 col-sm-12 col-md-12 flip pull-right">
            <a href="download/docs/ezharNameKarshenasi.docx" style="display: block;margin-top: 20px;margin-bottom: 20px;"><img src="images/docx.gif" />فرم اظهارنامه کارشناسی</a>
            <a href="download/docs/drakhasteSodoreParvaneTasis.docx" style="display: block;margin-top: 20px;margin-bottom: 20px;"><img src="images/docx.gif" />فرم درخواست صدور پروانه تاسیس</a>
            <a href="download/docs/taghazayeSodooreParvane.docx" style="display: block;margin-top: 20px;margin-bottom: 20px;"><img src="images/docx.gif" />فرم تقاضای صدور پروانه موافقت اصولی آبزیان</a>
            <a href="download/docs/sherkateSahamiIran.docx" style="display: block;margin-top: 20px;margin-bottom: 20px;"><img src="images/docx.gif" />فرم پروانه موافقت اصولی ماهیان سرد آبی در سیستم مدار بسته</a>
            <a href="download/docs/morafiName.docx" style="display: block;margin-top: 20px;margin-bottom: 20px;"><img src="images/docx.gif" />فرم معرفی نامه جهت در یافت اعتبارات بانکی</a>
            <a href="download/docs/نامه.docx" style="display: block;margin-top: 20px;margin-bottom: 20px;"><img src="images/docx.gif" />نامه</a>
        </div>

but some files name have unicode characters in their names.for example:C:\wamp\www\shilat-sistanL5\public\docs\نامه.docx.

in my routes file I have added this codes:

Route::get('download/{type}/{filename}', function($type,$filename)
{
    
    $file = public_path() .'\\'.$type. '\\' . $filename; // or wherever you have stored your PDF files
    return response()->download($file);
});

when trying to download نامه.docx file, I encountered with this error: FileNotFoundException in File.php line 37: The file "C:\wamp\www\shilat-sistanL5\public\docs\نامه.docx" does not exist.

I know this problem is related to php and not supporting utf-8 files. Anyone has a solution for this problem?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire