We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 32407
    • 35 Posts
    I am trying to get this snippet to open a url and save the contents locally but it never does anything.

    When I put this on a static php page ti works just fine.

    	if ($fp=fopen($url,"r"))
    	{
    		$content='';
    		while($line=fread($fp,1024))
    		{
    			$content .= $line;
    		}
    		$file = fopen("directory.xml", "w");
    		fwrite($file, $content);
    		fclose($file);
    	}
    
      • 32407
      • 35 Posts
      I have even tried curl and it still does the same thing:

      function get_data($url) 
      	{
      		try
      		{
      		$ch = curl_init();
      		$timeout = 5;
      		curl_setopt($ch,CURLOPT_URL,$url);
      		curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
      		curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
      		$data = curl_exec($ch);
      		curl_close($ch);
      		return $data;
      		}
      		catch (Exception $e)
      		{
      			return $e;
      		}
      	}
      	$content = get_data($url);
        • 32407
        • 35 Posts
        I got it work

        	function get_data($url) 
        	{
        		try
        		{
        			$ch = curl_init();
        			$timeout = 5;
        			curl_setopt($ch,CURLOPT_URL,$url);
        			curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
        			curl_setopt($ch,CURLOPT_CONNECTTIMEOUT,$timeout);
        			$data = curl_exec($ch);
        			curl_close($ch);
        			return $data;
        		}
        		catch (Exception $e)
        		{
        			return $e;
        		}
        	}
        	$content = get_data($url);
        	$file = fopen("file.xml", "w");
        	fwrite($file, $content);
        	fclose($file);