+ Reply to Thread
Results 1 to 4 of 4
Like Tree2Likes
  • 1 Post By bux.tombulka27
  • 1 Post By bux.tombulka27

Thread: Problem with file_get_contents

  1. #1
    bux.tombulka27 is offline x10Hosting Member bux.tombulka27 is an unknown quantity at this point
    Join Date
    Dec 2011
    Posts
    3

    Problem with file_get_contents

    Hello everyone.
    I am trying to run following php script:
    PHP Code:
    $date date('H i d m Y');    
    $date str_replace(" ""_"$date);        
    $image file_get_contents('http://82.177.67.40:65530/test/stok.jpg') or die('Could not get image');     
    $create  fopen("storage/$dateYear/$dateMonth/$dateDay/stok_$date.jpg"'w+') or die('Could not create file');     
    echo 
    '<br />saved stok_'.$date.'.jpg';    
    fputs($create$image) or die('Could not save to file');     
    fclose($create);     
    unset(
    $image); 
    It works perfectly on my localhost server, but when i tried to run it on x10hosting account it shows "Could not get image" which means that file_get_contents don`t work well. What am I doing wrong?

    Thanks for help!
    karimirt47 likes this.

  2. #2
    macz.diamonds61 is offline x10Hosting Member macz.diamonds61 is an unknown quantity at this point
    Join Date
    Dec 2011
    Location
    Texas :-(
    Posts
    21

    Re: Problem with file_get_contents

    I am not 100% certain of this but I have read in the past that x10hosting doesn't allow file_get_contents from outside it's network (probably for security reasons). I would suggest rather than connecting to an outside server to create a dir on the x10host and use it's file path.

    $image = file_get_contents('path_to_local_file') or die('Could not get image');
    I am new to the x10 community so I only know what I have read or at least what I think I remember reading.

  3. #3
    bux.tombulka27 is offline x10Hosting Member bux.tombulka27 is an unknown quantity at this point
    Join Date
    Dec 2011
    Posts
    3

    Re: Problem with file_get_contents

    I use this now:
    PHP Code:
        function save_image($inPath,$outPath)    {         $in=fopen($inPath"rb");        $out=fopen($outPath"wb");        while ($chunk fread($in,8192))        {        fwrite($out$chunk8192);    }    fclose($in);    fclose($out);    }
        
    save_image('http://82.177.67.40:65530/test/stok.jpg','image.jpg') or die('error'); 
    It don`t use file_get_contents, allow_url_fopen is turned on on x10hosting server, but It still saves empty files. Everything is working perfectly on my localhost server.
    dinomirt96 likes this.

  4. #4
    macz.diamonds61 is offline x10Hosting Member macz.diamonds61 is an unknown quantity at this point
    Join Date
    Dec 2011
    Location
    Texas :-(
    Posts
    21

    Re: Problem with file_get_contents

    Try this:

    <?php
    $url = 'http://82.177.67.40:65530/test/stok.jpg';
    $img = 'stok.jpg';
    file_put_contents($img, file_get_contents($url));

    ?>

    Sorry I don't know how to do the whole php code thing.

+ Reply to Thread

Similar Threads

  1. file_get_contents ?
    By edyboss92 in forum Free Hosting
    Replies: 0
    Last Post: 05-13-2011, 07:56 AM
  2. file_get_contents
    By altulek47 in forum Free Hosting
    Replies: 0
    Last Post: 11-15-2010, 01:57 AM
  3. Please allow file_get_contents
    By hsr_sr in forum Feedback and Suggestions
    Replies: 0
    Last Post: 09-24-2009, 01:17 AM
  4. file_get_contents()
    By driveflexfuel in forum Programming Help
    Replies: 4
    Last Post: 04-15-2009, 06:16 PM
  5. file_get_contents - php
    By Lucipher6 in forum Programming Help
    Replies: 2
    Last Post: 07-29-2008, 06:50 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
x10hosting free hosting for the masses
dedicated servers