[SOLVED] Function for delete file?

Hi,

I need to develop a function to delete file from server. I already know file_exist, unlink, functions etc. How to delete a file via PHP? - Stack Overflow

But filename can have specials chars : ’ ( ) and space and it’s more complicated.

Is it possible to find function use by scriptcase ? I don’t want reinvent the wheel :wink:

Thanks

They only PHP function I use to delete files is: unlink(‘filename’);

Unlink is the way to go. Your #1 reference is: PHP: unlink - Manual

Hello Guys,

I know this function, but when filename contains special chars is not possible to delete file.

Example : my document(1).pdf

I can use addcslashes function but how find all possibilities ?

Thanks

It sounds like the incoming data, where you get the filename, is not UTF-8 where the filesystem is using UTF-8 for filenames. In that case you need to use iconv(). If the input encoding is ISO-8859-1 then you can also use utf8_encode()

Use iconv. utf8_encode is deprecated in higher PHP versions.

Hi,

You seem to say that with a file with this name :

Formulaire d’appréciation (1).pdf

There is no problem to use unlink("/var/www/_lib/files/doc/Formulaire d’appréciation (1).pdf"); ?

I am not sure.

Thanks

My wild guess would be that if ‘file_exists’ formulates that the file exists that unlink should work. I don’t know if the apostrophe is an issue here, but you can write a small php program to test.

Hi,

I would have especially liked to be able to find the function used in Scriptcase which manages all the existing scenarios and reuse it.

Thanks.

Sorry, finally I can pass any file as parameter in the unlink() function and it works.

My problem was that the starting path was wrong: /var/www/html/_lib/files/doc/ (prod) and /var/www/scriptcase/files/doc/ (dev)

Now I use : $_SESSION[‘scriptcase’][‘my_app_name’][‘glo_nm_path_doc’]

Thanks