我創建了一個插件作爲第三方來使用wordpress網站在主站點上使用acomodate系統。所以情景是: 當用戶點擊提交系統時,它也將添加到WordPress的網站,它運作完美,沒有任何問題。但是當我試圖通過wp_insert_attachment
設置功能的圖像它讓我給像使用wp_insert_attachment時的URL錯誤
http://xxxxx.com/wp-content/uploads/http://xxxxx.com/system/media/.../xx.jpg
一個網址我想成爲的人只有http://xxxxx.com/system/media/.../xx.jpg保存爲特色的形象,是有可能這樣做? 這裏是我當前的腳本
if($pt == "pictures"){
$filename_url = $_GET["dml_file"];
$mime = wp_check_filetype($filename_url, null);
$data = array(
'post_mime_type' => $mime['type'],
'post_title' => preg_replace('/\.[^.]+$/', '', basename($_GET["dml_file"])),
'post_content' => '',
'post_status' => 'inherit'
);
$attachment_id = wp_insert_attachment($data, $filename_url, $pid);
update_post_meta($pid, $custom_field, $attachment_id);
}else{
update_post_meta($pid, $custom_field, $_GET["dml_file"]);
}
我曾嘗試使用file_get_contents
和file_put_contents
創造WP安裝映像,但我不希望這樣。
該系統提交此:
http://user:[email protected]/wp-content/plugins/dml3rdparty/dmlsubmit.php?dml_save=save&dml_file=http://xxx.xxx.xxx.xxx/dml/assets/media/Accreditation/download.d15bdf4e9e.jpg&dml_type=Print Quality Photos&dml_description=test|download.jpg&dml_status=publish
很明顯,你的'filename_url'需要進行修整。 – brasofilo
修剪,你是什麼意思?我想擺脫http://xxxxx.com/wp-content/uploads/ part –
*動詞:通過刪除不規則或不需要的部分,使(某物)整齊或具有所需的大小或形式*執行'var_dump ($ filename_url);死();'檢查出來。 – brasofilo