编码或某事逃脱在PHP中的斜杠(/)输入? [英] Encode or somthing to escape slash (/) input in php?

查看:73
本文介绍了编码或某事逃脱在PHP中的斜杠(/)输入?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里堆.

我想创建一个文件,我使用title_input作为文件名,但是在将文件创建到特定文件夹时遇到问题.

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.

示例:

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

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

错误:

警告:fopen(C:/Program Files/xampp/htdocs/myweb/product/Multi-Purpose Day/Night Security.php):无法打开流:C:\ Program Files \ xampp中没有此类文件或目录第28行的\ htdocs \ myweb \ admin \ process \ do_upload.php

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

无法打开文件!

推荐答案

您始终可以对文件名进行编码,以创建有效的文件名,然后在读取文件名后对文件名进行解码,这就像对文件名进行base64操作一样简单之前和之后.

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

这篇关于编码或某事逃脱在PHP中的斜杠(/)输入?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆