blackhacker
Forum Replies Created
-
Forum: Plugins
In reply to: New plugin avaiable, dbfileGreat plugin !! Especially if you blog is on a shared hosting service. I wrote a hack that lets you give an URL and the plugin will callout to URL and import the “file” to the DB.
edit dbfile.inc of the plugin like so:
in the editFile function:
locate the following:
<tr>
<td>File:</td>
<td><input type="file" name="FileData" /></td>
</tr>
and insert the this after it:
<tr>
<td>URL:</td>
<td><input type="text" name="FileURL" maxlength="400" /></td>
</tr>
In the receiveFile function locate:
if ($userfile != "") {
...
}
add the following else if condition :
} else if ($url != "") {
$url_array = parse_url($url);if ($url_array["scheme"] != 'http') {
die ('Only HTTP is supported at this time');
}$url_path_array = pathinfo($url_array["path"]);
$name = $url_path_array['basename'];
$extension = $url_path_array['extension'];if (!in_array(strtolower($extension), $fileTypes, true)) {
die('Invalid file type');
}$ch = curl_init();
// set URL and other appropriate options
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);// Perform remote request retieve contents, mime type & return code of URL
$fileContents = addslashes(curl_exec($ch));
$userfile_type = curl_getinfo ( $ch, CURLINFO_CONTENT_TYPE );
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);if ($http_code >= 300) {
die ("remote request returned HTTP code $http_code");
}// close curl resource, and free up system resources
curl_close($ch);
$fileSql = ", name=\"{$name}\", mimeType=\"{$userfile_type}\", content=\"{$fileContents}\"";
} else {
die ("Enter a URL or a local file path.");
}