My code retrieves photos from urls and using file_put_contents add them to the current directory, but I need it to add them to /wordpress/wp-content/uploads where wordpress save the manually uploaded files.
$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'];
I even copied the following part in my index file but it did not solve the problem
if(! function_exists('wp_upload_dir'))
{
define('WP_USE_THEMES',false);
require 'wordpress/wp-load.php';
}
Some ideas:
ref: http://codex.wordpress.org/Function_Reference/wp_upload_dir
ref: http://php.net/manual/en/function.rename.php
UPDATE
I guess that you are working outside of WP. Try this to get
wp_upload_dir()and all WP functionality before your code: