我的代码从 url 中检索照片并使用 file_put_contents 将它们添加到当前目录,但我需要将它们添加到 /wordpress/wp-content/uploads 中 wordpress 保存手动上传的文件的位置。
$Address = "www.xxx.com/" . $file;
$ch = curl_init();
curl_setopt($ch, CURLOPT_POST, 0);
curl_setopt($ch, CURLOPT_URL, $file);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$url = curl_exec($ch);
curl_close($ch);
$location = "/wordpress/wp-content/uploads/2013/a.jpg";
file_put_contents($location, file_get_contents($url));
if(! function_exists('wp_upload_dir'))
{
define('WP_USE_THEMES',false);
require 'wordpress/wp-load.php';
}
$upload_dir = wp_upload_dir();
echo $upload_dir['path'];
echo $upload_dir['url'];
echo $upload_dir['subdir'];
我什至在我的索引文件中复制了以下部分,但它没有解决问题
if(! function_exists('wp_upload_dir'))
{
define('WP_USE_THEMES',false);
require 'wordpress/wp-load.php';
}