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

守給你的承諾、 提交于 2020-01-30 12:11:14

问题


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:


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);


来源:https://stackoverflow.com/questions/34842762/encode-or-somthing-to-escape-slash-input-in-php

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!