Problem with file_get_contents

bux.tombulka27

New Member
Messages
3
Reaction score
0
Points
0
Hello everyone.
I am trying to run following php script:
PHP:
$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!
 

macz.diamonds61

New Member
Messages
21
Reaction score
0
Points
0
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.
 

bux.tombulka27

New Member
Messages
3
Reaction score
0
Points
0
I use this now:
PHP:
	function save_image($inPath,$outPath)	{    	 $in=fopen($inPath, "rb");   	 $out=fopen($outPath, "wb");    	while ($chunk = fread($in,8192))   	 {        fwrite($out, $chunk, 8192);    }    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.
 

macz.diamonds61

New Member
Messages
21
Reaction score
0
Points
0
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.
 
Top