RE: Warning: file_get_contents(): Filename cannot be empty

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 




> -----Original Message-----
> From: Ashley Sheridan [mailto:ash@xxxxxxxxxxxxxxxxxxxx]
> Sent: Monday, March 09, 2015 12:11 PM
> To: hadi
> Cc: 'Marcos Almeida Azevedo'; 'PHP General'
> Subject: Re:  Warning: file_get_contents(): Filename cannot be empty
> 
> On Mon, 2015-03-09 at 11:41 +0300, hadi wrote:
> >
> > > -----Original Message-----
> > > From: Ashley Sheridan [mailto:ash@xxxxxxxxxxxxxxxxxxxx]
> > > Sent: Monday, March 09, 2015 11:26 AM
> > > To: hadi
> > > Cc: 'Marcos Almeida Azevedo'; 'PHP General'
> > > Subject: Re:  Warning: file_get_contents(): Filename cannot be
> > > empty
> > >
> > > On Mon, 2015-03-09 at 11:18 +0300, hadi wrote:
> > > >
> > > > > -----Original Message-----
> > > > > From: Ashley Sheridan [mailto:ash@xxxxxxxxxxxxxxxxxxxx]
> > > > > Sent: Monday, March 09, 2015 10:46 AM
> > > > > To: hadi
> > > > > Cc: 'Marcos Almeida Azevedo'; 'PHP General'
> > > > > Subject: Re:  Warning: file_get_contents(): Filename cannot
> > > > > be empty
> > > > >
> > > > > On Mon, 2015-03-09 at 10:40 +0300, hadi wrote:
> > > > > >
> > > > > > > -----Original Message-----
> > > > > > > From: Ashley Sheridan [mailto:ash@xxxxxxxxxxxxxxxxxxxx]
> > > > > > > Sent: Monday, March 09, 2015 10:31 AM
> > > > > > > To: Marcos Almeida Azevedo
> > > > > > > Cc: hadi; PHP General
> > > > > > > Subject: Re:  Warning: file_get_contents(): Filename
> > > > > > > cannot be empty
> > > > > > >
> > > > > > > On Mon, 2015-03-09 at 15:25 +0800, Marcos Almeida Azevedo
> wrote:
> > > > > > > > > Hi every one,
> > > > > > > > >
> > > > > > > > > Im getting error while using  file_get_contents(): function.
> > > > > > > > >
> > > > > > > > > (Warning: file_get_contents(): Filename cannot be empty)
> > > > > > > > >
> > > > > > > > > Im using file_get_contents(): function to get urls links
> > > > > > > > > from
> > > > > > > > ($convert)
> > > > > > > > > variable.
> > > > > > > > >
> > > > > > > > > Here is my code
> > > > > > > > >
> > > > > > > > > <?php
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > error_reporting(E_ALL);
> > > > > > > > > ini_set("display_errors", 1);
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > $url = "http://www.sahafah.net/rss.php";;
> > > > > > > > >
> > > > > > > > >
> > > > > > > > > $rss = file_get_contents($url);
> > > > > > > > >
> > > > > > > >
> > > > > > > >
> > > > > > > > I believe file_get_contents should be used on a local file
> > > > > > > > and not remote or over http
> > > > > > >
> > > > > > > You can use file_get_contents() on URLs, but you need to
> > > > > > > have the allow_url_fopen ini setting on, which a lot of
> > > > > > > shared hosting providers won't allow. I don't remember if
> > > > > > > this is on or off by
> > > default.
> > > > > >
> > > > > > allow_url_fopen its on in my system, im using php on windows
> > > > > > with
> > > > > apache.
> > > > > >
> > > > > > What about im getting error from file_get_contents().....
> > > > > >
> > > > > >
> > > > > >
> > > > >
> > > > > I just made a quick test script and this works fine:
> > > > >
> > > > > <?php
> > > > > $url = "http://www.sahafah.net/rss.php";; $rss =
> > > > > file_get_contents($url);
> > > > >
> > > > > var_dump($rss);
> > > > >
> > > > >
> > > > > So it sounds like something on your system. Can you confirm that
> > > > > allow_url_fopen is on (with a phpinfo() call perhaps or an
> > > > > ini_get()
> > > > > call)
> > > > >
> > > > > Next thing to check is the Windows firewall. It could be
> > > > > blocking the outbound call.
> > > >
> > > >
> > > > Ash,
> > > >
> > > > Im ably to get the url data, but im not able to get the image from the
> url.
> > > > If you see my code you will notice that im grapping the image like
> > > > this,
> > > >
> > > > > $string2 = $item->description;
> > > > > preg_match('/http.*.jpg/',$string2,$match2);
> > > >
> > > > and convert match2 from array to string.
> > > >
> > > > > $convert = implode(",", $match2);
> > > >
> > > > And finally use  file_get_contents to get urls image from $convert
> > > >
> > > > // Read image path, convert to base64 encoding
> > > >     $imageData = base64_encode(file_get_contents($convert));
> > > >
> > > >     // Format the image SRC:  data:{mime};base64,{data};
> > > >     $src = 'data:
> > > > '.exif_imagetype($convert).';base64,'.$imageData;
> > > >
> > > >     // Echo out a sample image
> > > >     echo '<img src="', $src, '">';
> > > >
> > > >
> > >
> > > Ah, as your initial mail just had your entire code and the error
> > > with no line numbers, I assumed the first file_get_contents() call was the
> issue.
> > >
> > > What happens when you debug your code? What does $convert contain?
> > > Is it a string containing a URL?
> > Yes it containing string full path of url of the image like this
> > (http://www.alsahwa-yemen.net/pic_news/1/1_46777.jpg)
> >
> >
> 
> Does it definitely contain only that? Because the error you're getting is saying
> that it isn't a valid URL string and is in-fact an empty string. Have you checked
> that every single time you're calling it there is actually a valid URL in that
> variable?


Yes Ash, I have checked that. It have valid url in the variable $convert, you may try the code in ur system and see by ur self....


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php






[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux