Michael W
Michael W

Reputation:

Workaround for disabled php.ini features---

We are using shared hosting and the follow features are disabled.

file_uploads = Off
allow_url_fopen = Off
allow_url_include = Off

We are unable to change hosting and need to figure out some workarounds. The hosting co is also not able/willing to enable these features.

For example: We are calling 1 server from another in order to get content. So we do an include but since URL file include is disabled we are not sure what options we have to get the content on that second server and store it there using some kind of cache.

We control the content server fully (dedicated) so we can do whatever necessary just not sure if there is some easy solution to the problem.

Upvotes: 1

Views: 520

Answers (4)

anoopjohn
anoopjohn

Reputation: 518

You can solve your problem like this

a) Create mechanism in dedicated server to fetch any file (plus some kind of key based authentication and restrictions on paths where files can be fetched from)

eg: A url that says get_file?path=/path/to/file&key=security_key

b) Write a function to fetch this as if from a local file

function fetch_file($path) {
    $ch = curl_init("http://www.example.com/get_file?path=$path&key=security_key");
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, true);
    $output = curl_exec($ch);
    curl_close($ch);
    return $output;
}

Then you can eval the returned string and that would be like including the file

eval fetch_file($path);

Another solution to write to the server if php file upload is prevented is to ftp the file on to your server and include the file.

Upvotes: 0

Lasar
Lasar

Reputation: 5437

It depends on how locked down the server is. The given examples (using curl functions or fsockopen) should not be hampered by the restrictions you mentioned.

Upvotes: 0

someguy
someguy

Reputation:

Since you're looking to retrieve remote content the easiest way will be to write the functionality to fetch the content yourself with something like curl (php.net/curl)

Upvotes: 1

Related Questions