Php 用新名称替换URL文件名
我想用新修改的文件名替换URL文件名Php 用新名称替换URL文件名,php,file-io,Php,File Io,我想用新修改的文件名替换URL文件名 $url = 'http://p1.pichost.me/i/53/1770973.jpg'; $old_file_name = basename($fullBasePath); $new_file_name = old_file_name_modified; $fileName = renameUrl($url, old_file_name, new_file_name); 我检查了,但它不支持url。是否有其他php函数可用于此操作。您可以使用来反构造
$url = 'http://p1.pichost.me/i/53/1770973.jpg';
$old_file_name = basename($fullBasePath);
$new_file_name = old_file_name_modified;
$fileName = renameUrl($url, old_file_name, new_file_name);
我检查了,但它不支持url。是否有其他php函数可用于此操作。您可以使用来反构造URL,然后使用来重新构造它
例如:
$parts = parse_url($url);
$parts['path'] = urlencode($parts['path']);
$newurl = http_build_url($parts);
试试这个
$url = 'http://p1.pichost.me/i/53/1770973.jpg';
$old_file_name = basename($fullBasePath);
$new_file_name = old_file_name_modified;
$fileName = str_replace($old_file_name, $new_file_name, $url);
我不知道你想在这里实现什么?您正在尝试通过HTTP重命名远程文件吗?我的url中有文件名,空格
http://p1.pichost.me/i/53/1770973 name.jpg
。。。使用rawurlencode('http://p1.pichost.me/i/53/1770973 name.jpg')
,它与/
一起对整个过程进行编码,因此我尝试使用basename($fullBasePath)获取$filename
并使用rawurlencode($fullBasePath)对其进行编码,然后重命名url文件名