Instructions for modifying your customized installationThis requires several changes to 2 PHP files and 1 small change to a template file. There are several changes in each of the PHP files. Line numbers here were taken from the latest download and will be different once you modify your files.
Changes to member.php(starting at about line 549):
change this:
// Upload Media file
if (!empty($HTTP_POST_FILES['media_file']['tmp_name']) && $HTTP_POST_FILES['media_file']['tmp_name'] != "none") {
$new_name = $site_upload->upload_file("media_file", "media", $upload_cat);
if (!$new_name) {
$msg .= (($msg != "") ? "<br />" : "")."<b>".$lang['file_upload_error'].": ".$new_name."</b><br />".$site_upload->get_upload_errors();
$uploaderror = 1;
}
}
else {
$new_name = $remote_media_file;
}
Into this:
// Upload Media file
if (!empty($HTTP_POST_FILES['media_file']['tmp_name']) && $HTTP_POST_FILES['media_file']['tmp_name'] != "none") {
$new_name = $site_upload->upload_file("media_file", "media", $upload_cat);
if (!$new_name) {
$msg .= (($msg != "") ? "<br />" : "")."<b>".$lang['file_upload_error'].": ".$new_name."</b><br />".$site_upload->get_upload_errors();
$uploaderror = 1;
}
}
// BEGIN MODIFICATION by Brandon Checketts from www.webpipe.net bchecketts at hotmail dot com
elseif ($HTTP_POST_VARS['remote_media_file_download']) {
$new_name = $site_upload->download_file("remote_media_file", "media", $upload_cat);
}
// END BC MODIFICATION
else {
$new_name = $remote_media_file;
}
Change this (about line 573)
elseif ($config['auto_thumbnail'] == 1 && !empty($HTTP_POST_FILES['media_file']['tmp_name']) && $HTTP_POST_FILES['media_file']['tmp_name'] != "none" && !$uploaderror) {
Into this:
// BEGIN MODIFICATION by Brandon Checketts from www.webpipe.net bchecketts at hotmail dot com
elseif ($config['auto_thumbnail'] == 1 && !empty($_POST['remote_media_file']) && !$uploaderror) {
if ($direct_upload) {
$src = MEDIA_PATH."/".$cat_id."/".$new_name;
$dest = THUMB_PATH."/".$cat_id."/".$new_name;
}
else {
$src = MEDIA_TEMP_PATH."/".$new_name;
$dest = THUMB_TEMP_PATH."/".$new_name;
}
$do_create = 0;
if ($image_info = @getimagesize($src)) {
if ($image_info[2] == 1 || $image_info[2] == 2 || $image_info[2] == 3) {
$do_create = 1;
}
}
if ($do_create) {
require(ROOT_PATH.'includes/image_utils.php');
$convert_options = init_convert_options();
if (!$convert_options['convert_error']) {
$dimension = (intval($config['auto_thumbnail_dimension'])) ? intval($config['auto_thumbnail_dimension']) : 100;
$resize_type = (intval($config['auto_thumbnail_resize_type'])) ? intval($config['auto_thumbnail_resize_type']) : 1;
$quality = (intval($config['auto_thumbnail_quality']) && intval($config['auto_thumbnail_quality']) <= 100) ? intval($config['auto_thumbnail_quality']) : 100;
if (create_thumbnail($src, $dest, $quality, $dimension, $resize_type)) {
$new_thumb_name = $new_name;
}
}
}
}
// END BC MODIFICATION
elseif (($config['auto_thumbnail'] == 1 && !empty($HTTP_POST_FILES['media_file']['tmp_name']) && $HTTP_POST_FILES['media_file']['tmp_name'] != "none" && !$uploaderror) ||
($config['auto_thumbnail'] == 1 && !$empty($_POST['remote_media_file']) && !empty($_POST['remote_media_file_download']) && !$uploaderror) ) {
Changes to includes/upload.phpAbout line 44, Add this function before the Upload class is defined:
// BEGIN MODIFICATION by Brandon Checketts from www.webpipe.net bchecketts at hotmail dot com
function move_downloaded_file($file_name, $destination) {
return copy($file_name, $destination) ? 1 : 0 ;
}
// END BC MODIFICATION
class Upload {
Change this (about line 103)
$ok = move_uploaded_file($this->upload_file, $this->upload_path[$this->image_type]."/".$this->file_name);
to this
// BEGIN MODIFICATION by Brandon Checketts from www.webpipe.net bchecketts at hotmail dot com
if(isset($_POST['remote_media_file_download']) && $_POST['remote_media_file_download']) {
$ok = move_downloaded_file($this->upload_file, $this->upload_path[$this->image_type]."/".$this->file_name);
} else {
$ok = move_uploaded_file($this->upload_file, $this->upload_path[$this->image_type]."/".$this->file_name);
}
// END BC MODIFICATION
Change this (line 122)
$ok = move_uploaded_file($this->upload_file, $this->upload_path[$this->image_type]."/".$this->file_name);
to this:
// BEGIN MODIFICATION by Brandon Checketts from www.webpipe.net bchecketts at hotmail dot com
if(isset($_POST['remote_media_file_download']) && $_POST['remote_media_file_download']) {
$ok = move_downloaded_file($this->upload_file, $this->upload_path[$this->image_type]."/".$this->file_name);
} else {
$ok = move_uploaded_file($this->upload_file, $this->upload_path[$this->image_type]."/".$this->file_name);
}
// END BC MODIFICATION
Add this function on line 226 before the "function check_file_extension($extension = "") { line
// START MODIFICATIONS by Brandon Checketts from www.webpipe.net bchecketts at hotmail dot com
function download_file($field_name, $image_type, $cat_id = 0, $file_name = "")
{
$this->field_name = $field_name;
$this->image_type = $image_type;
if ($cat_id) {
$this->upload_path['thumb'] = THUMB_PATH."/".$cat_id;
$this->upload_path['media'] = MEDIA_PATH."/".$cat_id;
}
else {
$this->upload_path['thumb'] = THUMB_TEMP_PATH;
$this->upload_path['media'] = MEDIA_TEMP_PATH;
}
// Figure out an appropriate file name
if ($file_name != "") {
ereg("(.+)\.(.+)", $file_name, $regs);
$this->name = $regs[1];
ereg("(.+)\.(.+)", $this->HTTP_POST_FILES[$this->field_name]['name'], $regs);
$this->extension = $regs[2];
$this->file_name = $this->name.".".$this->extension ;
}
else {
$file_only = $_POST[$field_name];
$file_only = preg_replace("/.*\//","",$file_only);
$this->file_name = $file_only;
$this->file_name = ereg_replace(" ", "_", $this->file_name);
$this->file_name = ereg_replace("%20", "_", $this->file_name);
$this->file_name = preg_replace("/[^-\._a-zA-Z0-9]/", "", $this->file_name);
ereg("(.+)\.(.+)", $this->file_name, $regs);
$this->name = $regs[1];
$this->extension = $regs[2];
}
$url = $_POST[$field_name];
$ch = curl_init($url);
$save_file = "/tmp/" . $this->file_name;
$fp = fopen($save_file,"w");
curl_setopt($ch, CURLOPT_FILE, $fp);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_exec($ch);
$this->mime_type = curl_getinfo($ch,CURLINFO_CONTENT_TYPE);
curl_close($ch);
fclose($fp);
if ($this->save_downloaded_file($save_file)) {
return $this->file_name;
}
else {
return false;
}
}
// END BC MODIFICATIONS
Changes to your template file (member_uploadform.html)Add this line in the section where it prompts for the URL (line 27 for for the 4blue_orange1 template)
<!-- BEGIN MODIFICATION by Brandon Checketts from www.webpipe.net bchecketts at hotmail dot com -->
<input type="checkbox" name="remote_media_file_download">Save a copy locally <br />
<!-- END BC MODIFICATION -->
Thanks,
Brandon Checketts
bchecketts at hotmail dot com
www.webpipe.net System Administrator
Hosting accounts at Webpipe.net are fully compatible with 4images!