This topic is locked

Replace spaces in files before upload

8/18/2018 11:47:36 AM
PHPRunner General questions
A
alfonso authorDevClub member

How can I replace spaces in files with "-" before upload? For example, a file called "my file 2018.pdf" rename it to "my-file-2018.pdf".

Thanks

HJB 8/18/2018



How can I replace spaces in files with "-" before upload? For example, a file called "my file 2018.pdf" rename it to "my-file-2018.pdf".

Thanks


https://stackoverflow.com/questions/10605896/replace-spaces-with-underscores-in-uploaded-file
... for inspiration ...

A
alfonso authorDevClub member 8/19/2018



https://stackoverflow.com/questions/10605896/replace-spaces-with-underscores-in-uploaded-file
... for inspiration ...


Thanks. I mean what code must I put in function BeforeProcessAdd($pageObject)

HJB 8/19/2018



Thanks. I mean what code must I put in function BeforeProcessAdd($pageObject)


https://xlinesoft.com/phprunner/docs/rename_uploaded_file.htm
... on correct EVENT section ...
$filename = str_replace(' ', '-', $filename);
... has to be additionally puzzled in ...

A
alfonso authorDevClub member 8/21/2018



https://xlinesoft.com/phprunner/docs/rename_uploaded_file.htm
... on correct EVENT section ...
$filename = str_replace(' ', '-', $filename);
... has to be additionally puzzled in ...


I wrote this code:
$filename = $values["foto"];
$values["foto"] = str_replace(' ', '-', $filename);
and my file called "my photo 2018.jpg" save in database as "my-photo-2018.jpg". Perfect. But phisical my file is still with spaces

Any idea?
I try this:
$filename = $values["foto"];
$values["foto"] = str_replace(' ', '-', $filename);
$newFileName = "../fotografias/".$values["foto"];

rename($fileName, getabspath($newFileName));
But name of file is still with spaces