Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9197789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T22:08:50+00:00 2026-06-17T22:08:50+00:00

My code retrieves photos from urls and using file_put_contents add them to the current

  • 0

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';
                    }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T22:08:51+00:00Added an answer on June 17, 2026 at 10:08 pm

    Some ideas:

    $uploads = wp_upload_dir();
    $upload_path = $uploads['baseurl']; // get uploads dir
    
    rename("a.jpg", trailingslashit($upload_path) . "a.jpg"); // move
    

    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:

    if ( ! function_exists('wp_upload_dir'))
    {
        define('WP_USE_THEMES', false);
        require PATH_WP_DIR . '/wp-load.php';
        // ex: require '/wordpress/wp-load.php';
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im just using the graph.facebook.com code to display photos from an album but i
I've rolled my own code to retrieve data from remote URLs using a HttpURLConnection.
I'm using the following code to retrieve a json string from my webserver: var
I'm using a standard couple of lines of code to retrieve a key from
following code i used to retrieve Image from database through linq query but i
I've been trying out PhoneGap on iOS using the following example code from the
I want to get images from a flickr rss but this code won't get
I have an ImageHandler class that I am using to retrieve photos from an
We want to import contacts photos from google API. Following code was working for
I'm getting data from DB and displayed in a GridView fine. But I need

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.