Encode or somthing to escape slash (/) input in php?

714 Views Asked by At

I'm stack here.

I want to create a file and i use title_input as file_name, but i have problem when create the file to specific folder.

Example:

$file_name="Multi purpose Day/Night Security";

$myfile = fopen($_SERVER['DOCUMENT_ROOT']."/myweb/product/".$file_name.".php", "wb") or die("Unable to open file!");

Error:

Warning: fopen(C:/Program Files/xampp/htdocs/myweb/product/Multi-Purpose Day/Night Security.php): failed to open stream: No such file or directory in C:\Program Files\xampp\htdocs\myweb\admin\process\do_upload.php on line 28

Unable to open file!

1

There are 1 best solutions below

0
AudioBubble On BEST ANSWER

You can always just encode the filename to make a valid filename and then decode the filename after you have read from it and this could be as simple as base64ing the filename before and after.

$filename = 'Multi purpose Day/Night Security';

// Raw filename
$filename = base64_encode($filename);

// Original filename
$filename = base64_decode($filename);