| View previous topic :: View next topic |
| Author |
Message |
heshys Novato


Joined: Dec 16, 2003 Posts: 9
|
Posted: Tue Apr 26, 2005 5:24 pm Post subject: fopen is disabled so module doesn't work |
|
|
My host has disabled PHP's allow_url_fopen which includes the "fopen" command for security reasons which doesn't allow this module to work. They instead recommend curl functions.
Here's an example:
http://blog.unitedheroes.net/archives/p/1630/
| Code: | $curl_handle = curl_init();
// Where should we get the data?
curl_setopt ($curl_handle, CURLOPT_URL, ‘http://example.com’);
// This says not to dump it directly to the output stream, but instead
// have it return as a string.
curl_setopt ($curl_handle, CURLOPT_RETURNTRANSFER, 1);
// the following is optional, but you should consider setting it
// anyway. It prevents your page from hanging if the remote site is
// down.
curl_setopt ($curl_handle, CURLOPT_CONNECTTIMEOUT, 1);
// Now, YOU make the call.
$buffer = curl_exec($curl_handle);
// And tell it to shut down (when your done. You can always make more
// calls if you want.)
curl_close($curl_handle);
// This is where i’d probably do some extra checks on what i just got.
// Paranoia pays dividends.
print $buffer; |
Can this be made to work with this?[/quote] |
|
| Back to top |
|
 |
EJDiaz Administrador


Joined: May 24, 2002 Posts: 295 Location: Florida
|
Posted: Fri Jun 10, 2005 8:12 pm Post subject: Cure for allow_url_fopen blues! |
|
|
Open /includes/NukeAmazon/functions.php
replace function AMZ_file_get_contents($filename) with the following code.
| Code: |
function AMZ_file_get_contents($url)
{
////
// Fetch URL using whathever method is available. Returns content of page on success, false on failure
# function tep_fetch_url($url) {
if(function_exists('curl_init')) {
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
$page = curl_exec($ch);
curl_close($ch);
return utf8_decode($page);
} else if(ini_get('allow_url_fopen')) {
$page = file($url);
$page = implode('', $page);
return utf8_decode($page);
} else {
$page = '';
$elements = parse_url($url);
if(strtolower($elements['scheme']) != 'http') {
return false;
}
$fp = @fsockopen($elements['host'], isset($elements['port']) ? $elements['port'] : 80);
if(!$fp) {
return false;
}
fputs($fp, sprintf("GET %s HTTP/1.0\nHost: %s\n\n",
$elements['path'] . (isset($elements['query']) ? '?' . $elements['query'] : ''),
$host
));
$headers = true;
while(!feof($fp)) {
$line = fgets($fp, 4096);
if(chop($line) == "") {
$headers = false;
}
if(!$headers) {
$page .= $line;
}
}
fclose($fp);
return utf8_decode($page);
}
return false;
}
|
Edited to correct the second line "AMZ_file_get_contents($filename)" _________________ ~Edgardo
PrecioGasolina.com | E.J. Stores
Last edited by EJDiaz on Tue Aug 23, 2005 7:04 pm, edited 1 time in total |
|
| Back to top |
|
 |
heshys Novato


Joined: Dec 16, 2003 Posts: 9
|
Posted: Sat Jun 11, 2005 9:34 pm Post subject: |
|
|
| Thanks that worked perfectly... |
|
| Back to top |
|
 |
shizznitbiznatch Novato


Joined: Aug 23, 2005 Posts: 7
|
Posted: Tue Aug 23, 2005 11:31 am Post subject: Does not work. |
|
|
There is no function AMZ_file_get_contents($url) in functions.php.
Only reference to fopen is code below:
| Code: |
function AMZ_file_get_contents($filename)
{
$fp = @open($filename, "r");
if (!($fp))
{
return 0;
}
while (!feof($fp))
{
$temp .= utf8_decode(fread($fp, 4096));
}
fclose($fp);
return $temp;
}
|
Only reference to AMZ_file_get_contents($url) is found just above that in functions.php:
| Code: |
$String = AMZ_file_get_contents($URL);
|
Need a version that uses curl when fopen is off. I have been waiting over a year for a solution! I'm about ready to remove module. It has been broken since admin disabled fopen. Is anyone working on this?!
Thanks |
|
| Back to top |
|
 |
EJDiaz Administrador


Joined: May 24, 2002 Posts: 295 Location: Florida
|
Posted: Tue Aug 23, 2005 7:13 pm Post subject: |
|
|
In the speed of getting this issue posted I typed $url instead of $filename. I have edited the post to show the correct text.
Sorry for any confusion $url may have caused.  _________________ ~Edgardo
PrecioGasolina.com | E.J. Stores |
|
| Back to top |
|
 |
shizznitbiznatch Novato


Joined: Aug 23, 2005 Posts: 7
|
Posted: Wed Aug 24, 2005 12:03 pm Post subject: |
|
|
Thanks for clearing that up!
I made the change but was still getting the same error and found that the version number in my index.php file:
$AMZCodeVer = "2.7.2";
did not match the version in my database "amazon_cfg" file which was listed as AMZVer 2.7. Once I corrected that the module appeared.
However, I have another problem now- I get the following error:
Warning: getimagesize(): URL file-access is disabled in the server configuration....
This is causing product images not to be displayed. When fopen was set to off, URL file-access was also disabled for the same security reason.
I remember I had to rewrite another script to get around this...will have to look it up, can't remember what changes I made.
Any help would be appreciated! |
|
| Back to top |
|
 |
EJDiaz Administrador


Joined: May 24, 2002 Posts: 295 Location: Florida
|
Posted: Wed Aug 24, 2005 6:46 pm Post subject: |
|
|
Did you do the sql upgrade when upgrading from 2.7 to 2.7.2?
| Quote: | | I remember I had to rewrite another script to get around this...will have to look it up, can't remember what changes I made |
When you find it, please post it here for the benefit of all. _________________ ~Edgardo
PrecioGasolina.com | E.J. Stores |
|
| Back to top |
|
 |
112502 Novato


Joined: Oct 02, 2003 Posts: 5
|
Posted: Fri Nov 11, 2005 12:18 pm Post subject: |
|
|
While we're on this fopen problem ...
With fopen() disabled (which it should be), using the curl method to grab XML works great. Unfortunately, the "getImageSize" function gets disabled where the code does "getImageSize($url)" ... and we end up with no thumbnails.
So .. umm .. how about a patch for this one?  |
|
| Back to top |
|
 |
shizznitbiznatch Novato


Joined: Aug 23, 2005 Posts: 7
|
Posted: Fri Nov 11, 2005 8:35 pm Post subject: re: no thumbnails |
|
|
Image problem solved!
Did a little digging and came up with a workaround for image display problem. Did a search of code in includes/NukeAmazon/functions.php and made the following changes. Images now displaying for products.
Worked for me in combination with curl option since fopen was disabled. getImageSize function still works for the most part, just not in fetching product images as $ImageUrl.
Must use $arr['imageurlsmall'] and $arr['imageurlmedium'] instead. Only had to make the 3 changes below in functions.php to get it working on my server.
---------------------
Do a search and replace to fix code. FYI- I'm using NukeAmazon 2.7
small images fix:
(for May we suggest ... & related products, etc...)
Approx. Line 1394 replace
$Accessory .= $LinkStartStr ."<img src=\"" . $A_ImageUrl . "\" border=\"0\" alt=\"" . $A_ProductName . "\"></a>";
with
$Accessory .= $LinkStartStr ."<img src=\"" . $a_arr['imageurlsmall'] . "\" border=\"0\" alt=\"" . $A_ProductName . "\"></a>";
Approx. Line 1517 replace
$content .= $LinkStartStr ."<br><img src=\"" . $S_ImageUrl . "\" border=\"0\" alt=\"" . $S_ProductName . "\"></a><br>";
with
$content .= $LinkStartStr ."<br><img src=\"" . $s_arr['imageurlsmall'] . "\" border=\"0\" alt=\"" . $S_ProductName . "\"></a><br>";
Medium images fix:
(for main product image)
Approx. Line 1066 replace
$content .= "<img src=\"" . $ImageUrl . "\" border =\"0\" alt=\"$ProductName\" >";
with
$content .= "<img src=\"" . $arr['imageurlmedium'] . "\" border =\"0\" alt=\"$ProductName\" width=\"80%\">"; |
|
| Back to top |
|
 |
112502 Novato


Joined: Oct 02, 2003 Posts: 5
|
Posted: Sat Nov 12, 2005 11:31 am Post subject: |
|
|
hmmm ... I'm using 2.7.2, and my line numbers don't anywhere near correspond with yours ---- I mean like, 1000 lines off. And, I'm still getting "Image Not Available" due to the Product Image bits checking "GetImageSize($url)" ...
I was able to get it to work, though not the best way, but simply commenting out the rather hefty Conditional in a couple of places ...
| Code: | # Product Image
// $size = GetImageSize($b_arr['imageurlsmall']);
// if ( $size[0] > 2 && $size[1] > 2 )
// {
$details['image'][$i] = $b_arr['imageurlsmall'];
// }
// else
// {
// $catalog = strtolower($ProductCatalog);
// $sql = "SELECT no_image FROM ".$prefix."_amazon_catalog WHERE r_catalog = '$catalog'";
// $result = $db->sql_query($sql);
// list($details['image'][$i]) = $db->sql_fetchrow($result);
// } |
| Code: | # Product Image
// $size = GetImageSize($arr['imageurlsmall']);
// if ( $size[0] > 2 && $size[1] > 2 )
// {
switch ($ImageSize)
{
case "small":
$ImageUrl = $arr['imageurlsmall'];
break;
case "medium":
$ImageUrl = $arr['imageurlmedium'];
break;
case "large":
$ImageUrl = $arr['imageurllarge'];
break;
}
// }
// else
// {
// $catalog = strtolower($ProductCatalog);
// $sql = "SELECT no_image FROM ".$prefix."_amazon_catalog WHERE r_catalog = '$catalog'";
// $result = $db->sql_query($sql);
// list($ImageUrl) = $db->sql_fetchrow($result);
// $NoImage = true;
// } | Then it works with fopen disabled --- an easy fix, that's easy to see. But who knows if I'm breaking something else... But ... at the same time, it's not likely you're going to end up with an image in their XML that's LESS than 2x2, so the issue is kinda moot.
The thing that'll actually fix it ... is to use curl to download the thumbnails to a cache, and do the GetImageSize against the local file. fopen's just too dangerous to leave turn on, especially with PHP-Nuke. |
|
| Back to top |
|
 |
shizznitbiznatch Novato


Joined: Aug 23, 2005 Posts: 7
|
Posted: Sat Nov 12, 2005 1:22 pm Post subject: re: GetImageSize |
|
|
Oops!
I forgot about that last part.
In functions.php I added a @ before all getimagesize so php doesn't broadcast it. (@getimagesize)
I'll try to find a "real fix" that works with curl, but for now at least I have images. I agree that using curl to write images to a /temp directory and then accessing it locally rather than by url is the real ticket.
Guess I have to dig a little deeper and see what I can come up with. I'll let you know if I come up with a fix... |
|
| Back to top |
|
 |
|