我想修改我在wordpress(Auto Featured Image插件)中使用的PHP腳本。
問題是,此腳本基於圖像的URL爲縮略圖創建文件名。PHP/regex:使用破折號而不是空格創建文件名的腳本
直到你得到空格的文件名和縮略圖像this%20Thumbnail.jpg
當瀏覽器去http://www.whatever.com/this%20Thumbnail.jpg
它轉換%20
的空間並沒有在服務器上沒有文件名由名稱(含空格)聲音很大。
爲了解決這個問題,我認爲我需要改變以下行,$ imageURL被過濾以將%20
轉換爲空格。聽起來對嗎?
這是代碼。也許你可以告訴我,如果我吠叫錯了樹。
謝謝!
<?php
static function create_post_attachment_from_url($imageUrl = null)
{
if(is_null($imageUrl)) return null;
// get file name
$filename = substr($imageUrl, (strrpos($imageUrl, '/'))+1);
if (!(($uploads = wp_upload_dir(current_time('mysql'))) && false === $uploads['error'])) {
return null;
}
// Generate unique file name
$filename = wp_unique_filename($uploads['path'], $filename);
?>
爲什麼不使用md5? – tttony 2012-03-24 06:24:42
其他_字符怎麼樣? – 2012-03-24 06:46:49
@ttony - 使用md5怎麼樣? – user1289585 2012-03-26 08:19:52