简体   繁体   English

如何使用php移至文件时删除文件名中的单引号

[英]How to remove single quote in filename while moving to the file using php

While uploading a file which contain single quote, when it moved to folder it add a \\ in it. 上载包含单引号的文件时,将其移到文件夹时在其中添加\\。 How to remove this slash using PHP 如何使用PHP删除此斜杠

eg. 例如。 my file which has a name video's.mp4 I remove slash and save it into mysql database but it moved to the folder contain video/s.mp4. 我的文件名为video's.mp4,我删除了斜杠并将其保存到mysql数据库中,但是将其移动到包含video / s.mp4的文件夹中。

When i try to download in frontend it showing that FILE NOT FOUND. 当我尝试在前端下载时,显示文件未找到。

I use following code to remove the slash : 我使用以下代码删除斜杠:

<?php
$remove[] = "'";
$name = str_replace( $remove, "", $name ); //name is file name i.e. videp's.mp4
?>

If the $name value comes from submitted form, it may have quotes escaped by the slash. 如果$name值来自提交的表单,则其斜杠可能会将引号转义。 Use stripslashes before replacing the quote: 在替换引号之前使用stripslashes

<?php
$remove[] = "'";
$name = str_replace( $remove, "", stripslashes( $name ) ); //name is file name i.e. videp's.mp4
?>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM