Jump to content

...but I'm not redeclaring a function!....


marklarah

Recommended Posts

Silly PHP....

 

Actually I'm more it's just silly me, probably something stupid I'm missing here, but what exactly could be wrong with this simple download script?

<?php

function http_get($url) 
{ 

    $url_stuff = parse_url($url); 
    $port = isset($url_stuff['port']) ? $url_stuff['port'] : 80; 

    $fp = fsockopen($url_stuff['host'], $port); 

    $query  = 'GET ' . $url_stuff['path'] . " HTTP/1.0\n"; 
    $query .= 'Host: ' . $url_stuff['host']; 
    $query .= "\n\n"; 

    fwrite($fp, $query); 

    while ($tmp = fread($fp, 1024)) 
    { 
        $buffer .= $tmp; 
    } 

    preg_match('/Content-Length: ([0-9]+)/', $buffer, $parts); 
    return substr($buffer, - $parts[1]); 
}
header("Content-Description: File Transfer");
header("Content-Type: application/x-rar-compressed");
header("Content-Transfer-Encoding: binary");
header("Content-Disposition: attachment; filename=test.rar");


http_get('file url goes here');

?>

 

I guess that should work, but I get

 

Fatal error: Cannot redeclare http_get()

 

on the line referring to the } that closes the function.

 

I can't see anything wrong with it...maybe you could point it out to me?

 

Cheers...

Link to comment
https://forums.phpfreaks.com/topic/157284-but-im-not-redeclaring-a-function/
Share on other sites

Thing i, I found this function on php.net so...I assumed it would be all working and such.

 

So you found that function in the user comments somewhere? Well that function you found the creator most likely did not have probably works the same as http_get if you do not have PECL installed. So it worked for him.

 

EDIT:

I do not think it works the same. Either way to use it, change your function name to something like :

 

function my_http_get

and your script should work just fine, given that function does what you want. If not maybe the http_get function does what you want and you do not have to use a user-defined function.

Thing i, I found this function on php.net so...I assumed it would be all working and such.

 

So you found that function in the user comments somewhere? Well that function you found the creator most likely did not have probably works the same as http_get if you do not have PECL installed. So it worked for him.

 

EDIT:

I do not think it works the same. Either way to use it, change your function name to something like :

 

function my_http_get

and your script should work just fine.

 

http://php.oregonstate.edu/manual/en/features.remote-files.php

 

Ctrl+f: 29-Apr-2008 01:18 05-Aug-2003 12:25 to find the post

 

So I just renamed the function, and it finished loading the page, in a time  that might of seemed it could have downloaded the file, but the file in my downloads folder is just Zero kilobytes

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.