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 8681717
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:34:58+00:00 2026-06-12T21:34:58+00:00

I have developed a wordpress plugin which uses file_get_contents() to retrieve images from distant

  • 0

I have developed a wordpress plugin which uses file_get_contents() to retrieve images from distant url and save it in the local folder using fwrite function. The image file gets saved in a local folder so it can be referenced later.

This works fine in one webserver 1. But when I installed the plugin in wordpress maintained in a different new webserver 2, the file gets created in the local folder but seems it gets corrupted. The file is created properly for images which are less than 100kb i guess, but larger files which are properly created in the former webserver 1 are corrupted when retrieved and created in server 2.

Below is the code I use to retrieve images and save to local folder:

//$imgurl = url of the image file and $upload_path 
// is path where image will be stored

$file = file_get_contents($imgurl) or die('File too large or inacessible');
$myFile = $upload_path . "\internal\folder\structure\\" . $file_name;
$fh = fopen($myFile, 'w') or die("Error");
$fwrite = fwrite($fh, $file);

if($fwrite === false)
{
    echo "error";
}
else
{
    echo "file has been created ".$file_name;
}

fclose($fh);

In server 1 this works fine, but in server 2, the file gets created but cant open it because it is corrupted. I guess this probably should have to do with the php configuration of the server 2 but I am not very sure so I am looking forward for your help.

  • 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-12T21:35:00+00:00Added an answer on June 12, 2026 at 9:35 pm

    There could be several reasons

    1. PHP Error generated by something on server2

    2. some output like newline or space before your function

    read http://php.net/manual/en/function.file-get-contents.php for hint

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have developed a wordpress plugin that uses jquery. This plugin have some javascript
I have developed a WordPress plugin which needs to perform additional processing when a
I have developed a wordpress plugin , i am planning to update the plugin.
I have developed a wordpress plugin that looks through a bunch of html and
I have a custom developed WordPress plugin that is using jQuery 1.4 and for
I have a Wordpress site that uses a JQuery plugin called Hover-Caption ( https://github.com/coryschires/hover-caption
I have developed whole my website in wordpress and my site url is like
I have just developed a wordpress plugin and it is all structured within a
I have developed a small administration page for game servers which you can add/remove/edit
I have developed a Java server using Eclipse that accepts TCP socket connection from

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.