Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] renaming, storing and accessing files: name problem
#1

(This post was last modified: 05-02-2022, 06:36 AM by dgvirtual.)

I suspect what I am going to write is not related to Codeigniter as such, and perhaps it is possible to Google it, but I lack what to google for Smile So please help me out Smile

In my application I allow users to upload files that are then renamed using user first name and last name in the file name as well as some other data. Any symbol can be used by the user, including utf-8 characters; punctuation marks could also happen...

the code to generate the new name for the file is:


PHP Code:
$first_name 'Donatąsš'
$last_name 'Glodenįs';
$type 'SC';
function 
safe_filename($str) {
    $str str_replace(' ''-'$str);
    $str urlencode($str);
    return $str;
}
$new_name safe_filename($type '_' $first_name '-' $last_name '.' $ext); 


And then the $new_name variable is stored in a db field and used to rename the file and move it to it's new place.

After this, the file I get is this:

SC_Donat%C4%85s%C5%A1-Gloden%C4%AFs.pdf

and the filename string in the DB field is:

SC_Donat%C4%85s%C5%A1-Gloden%C4%AFs.pdf

So it is the same.

But when I get that file name from db and output it on the page, I get it without the urlencode "formatting" for some reason:

SC_Donatąsš-Glodenįs.pdf

So, when I click on the link that includes that string, I get a 404 page. (this does not happen if the user name is made of ascii characters).

Could someone explain to me, how do I have to recode the string from DB on the page so that I get a working link to the file?
Donatas

Ha, while I would still like to understand how urlencode gets lost in codeigniter, I have just literraly minutes after posting the question found the answer to filename problems, which a function from url helper, called mb_url_title - https://codeigniter.com/user_guide/helpe...elper.html
==

Donatas G.
Reply
#2

Yep, I found that when searched through the CodeIgniter 4 Code.

Please add [SOLVED] to your topic title.
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB