site_account . "/www/images/site_images/"; $site_img_dir = "/home/" . $site->site_account . "/public_html/site_images/"; } // end if $top_level_dir = "/home/cpasites/public_html/images/"; $file_dir = realpath($_SESSION["admin"]["gallery_file_dir"]) . "/"; $img_dir = ($file_dir == $site_img_dir) ? (($site->site_status >= 50 && $site->site_status < 90) ? $site_url : "http://www.buildyourfirm.com/~" . $site->site_account) . "/site_images/" : str_replace("/home/cpasites/public_html/", "http://www.byftools.com/", $file_dir); $image_count = 0; $dir_count = 0; $files = array(); $dirs = array(); $allow_up_level = ($file_dir != $top_level_dir); if(!is_dir($file_dir) || $file_dir == "/") { $_SESSION["admin"]["warnings"][] = "There appears to be an error with the directory you are currently trying to view. (error code: 01103)"; } // end if if(!is_dir($img_dir)) { //$_SESSION["admin"]["warnings"][] = "There appears to be an error with the directory you are currently trying to view. (error code: 01104)"; } // end if // credit: http://php.net/manual/en/function.readdir.php if($handle = opendir($file_dir)) { // get all files while(false !== ($file = readdir($handle))) { if(!is_dir($file_dir . $file) && $file != "." && $file != "..") { // getimagesize was used to determine if the file was an image; commented out to handle all file types //if(getimagesize($file_dir . $file)) { //$files[filemtime($file_dir . $file)] = $file; $files[] = $file; //} // end if } // end if } // end while // sort by file creation time //krsort($files); rewind($handle); while(false !== ($file = readdir($handle))) { if(is_dir($file_dir . $file) && $file != "." && $file != ".." && Str::has_value($file)) { $dirs[] = $file; } // end if } // end while } // end if //sort($files); sort($dirs); $MAX_IMGS = 5; if($_SERVER["REQUEST_METHOD"] == "POST") { switch($_POST["cmd"]) { case "Submit": case "Upload": $file_upload = new Tbl(); $file_upload->fill($_POST); $errors = array(); $req_fields = array(); foreach($req_fields as $field_name => $field_label) { if(!Str::has_value($file_upload->$field_name)) { $errors[] = $field_label . " is a required field."; } // end if } // end foreach if(Str::has_value($file_dir)) { } else { $errors[] = "An error has occurred with the file upload directory."; } // end if $file_exts = array(); // handles $MAX_IMGS images with a file name like upload_file_# for($i = 1; $i <= $MAX_IMGS; $i++) { if((isset($_FILES["upload_file_" . $i])) && ($_FILES["upload_file_" . $i]["size"] > 0)) { if($_FILES["upload_file_" . $i]["name"] == "") { $errors[] = "Please choose a file for upload"; } else if($_FILES["upload_file_" . $i]["size"] == 0) { $errors[] = "Invalid file uploaded: " . $_FILES["upload_file_" . $i]["name"]; } else { preg_match("/\.([^.]+)$/", $_FILES["upload_file_" . $i]["name"], $m); $file_ext = strtolower($m[1]); if(!is_array($file_exts) || !(count($file_exts) > 0) || in_array($file_ext, $file_exts)) { //list($width) = getimagesize($_FILES["upload_file_" . $i]["tmp_name"]); } else { //$errors[] = "Invalid file uploaded: " . $_FILES["upload_file_" . $i]["name"]; } // end if } // end if } // end if } // end for if(count($errors) > 0) { $_SESSION["admin"]["errors"] = array_merge((array) $_SESSION["admin"]["errors"], $errors); $_SESSION["file_upload"]["object"] = serialize($file_upload); redirect($_SERVER["PHP_SELF"] . ((Str::has_value($_SERVER["QUERY_STRING"])) ? "?" . $_SERVER["QUERY_STRING"] : "")); } // end if // handles $MAX_IMGS images with a file name like upload_file_# for($i = 1; $i <= $MAX_IMGS; $i++) { if((isset($_FILES["upload_file_" . $i])) && ($_FILES["upload_file_" . $i]["size"] > 0)) { preg_match("/^(.+)\.([^.]+)$/", $_FILES["upload_file_" . $i]["name"], $m); $file_prefix = $m[1]; $file_suffix = $m[2]; $file_count = 0; do { $file_count++; $file_name = $file_prefix . (($file_count > 1) ? "_" . $file_count : "") . "." . $file_suffix; //$file_tn_name = $file_prefix . (($file_count > 1) ? "_" . $file_count : "") . "_tn." . $file_suffix; } // end do while(file_exists($file_dir . $file_name)); move_uploaded_file($_FILES["upload_file_" . $i]["tmp_name"], $file_dir . $file_name); //Image::resize($file_dir . $file_name, $file_dir . $file_tn_name, $TN_WIDTH, 0); //Image::resize($file_dir . $file_name, $file_dir . $file_name, $IMG_WIDTH, 0); $file_upload->{"upload_file_" . $i} = $file_name; $_SESSION["admin"]["messages"][] = $file_dir . $file_name . " successfully uploaded"; } // end if } // end for redirect($_SERVER["PHP_SELF"] . ((Str::has_value($_SERVER["QUERY_STRING"])) ? "?" . $_SERVER["QUERY_STRING"] : "")); break; case "OK": $file_upload = new Tbl(); $file_upload->fill($_POST); $errors = array(); switch($file_upload->action) { case "copy": $req_fields = array(); foreach($req_fields as $field_name => $field_label) { if(!Str::has_value($file_upload->$field_name)) { $errors[] = $field_label . " is a required field."; } // end if } // end foreach if(Str::has_value($file_dir) && Str::has_value($site_img_dir)) { } else { $errors[] = "An error has occurred with the file upload directory."; } // end if if(!is_array($file_upload->images) || !(count($file_upload->images) > 0)) { $errors[] = "Please select at least one image to copy to the account's site images directory."; } // end if if(count($errors) > 0) { $_SESSION["admin"]["errors"] = array_merge((array) $_SESSION["admin"]["errors"], $errors); $_SESSION["file_upload"]["object"] = serialize($file_upload); redirect($_SERVER["PHP_SELF"] . ((Str::has_value($_SERVER["QUERY_STRING"])) ? "?" . $_SERVER["QUERY_STRING"] : "")); } // end if foreach($file_upload->images as $image) { if(file_exists($file_dir . $image)) { copy($file_dir . $image, $site_img_dir . $image); $_SESSION["admin"]["messages"][] = $file_dir . $image . " successfully copied to " . $site_img_dir . $image . "."; } else { $_SESSION["admin"]["errors"][] = "An error occurred while attempting to copy " . $file_dir . $image . " (error code: 01101)"; } // end if } // end foreach redirect($_SERVER["PHP_SELF"] . ((Str::has_value($_SERVER["QUERY_STRING"])) ? "?" . $_SERVER["QUERY_STRING"] : "")); break; case "del": $req_fields = array(); foreach($req_fields as $field_name => $field_label) { if(!Str::has_value($file_upload->$field_name)) { $errors[] = $field_label . " is a required field."; } // end if } // end foreach if(Str::has_value($file_dir)) { } else { $errors[] = "An error has occurred with the current directory."; } // end if if(!is_array($file_upload->images) || !(count($file_upload->images) > 0)) { $errors[] = "Please select at least one image to delete."; } // end if if(count($errors) > 0) { $_SESSION["admin"]["errors"] = array_merge((array) $_SESSION["admin"]["errors"], $errors); $_SESSION["file_upload"]["object"] = serialize($file_upload); redirect($_SERVER["PHP_SELF"] . ((Str::has_value($_SERVER["QUERY_STRING"])) ? "?" . $_SERVER["QUERY_STRING"] : "")); } // end if foreach($file_upload->images as $image) { if(file_exists($file_dir . $image)) { unlink($file_dir . $image); $_SESSION["admin"]["messages"][] = $file_dir . $image . " successfully deleted."; } else { $_SESSION["admin"]["errors"][] = "An error occurred while attempting to delete " . $file_dir . $image . " (error code: 01102)"; } // end if } // end foreach redirect($_SERVER["PHP_SELF"] . ((Str::has_value($_SERVER["QUERY_STRING"])) ? "?" . $_SERVER["QUERY_STRING"] : "")); break; default: redirect($_SERVER["PHP_SELF"] . ((Str::has_value($_SERVER["QUERY_STRING"])) ? "?" . $_SERVER["QUERY_STRING"] : "")); } // end switch break; case "Add to Shortcuts": case "Add This Directory to Shortcuts": $data = new Tbl(); $data->fill($_POST); $errors = array(); $shortcut_url = "image_library.htm?dir=" . $_SESSION["admin"]["gallery_file_dir"] . "&mode=abs"; $shortcut_label = str_replace(array($top_level_dir, "/"), array("", " > "), $_SESSION["admin"]["gallery_file_dir"]); if(substr($shortcut_label, strlen($shortcut_label) - 3, 3) == " > ") { $shortcut_label = substr($shortcut_label, 0, -3); } // end if $query = "SELECT * FROM `admin_shortcut` WHERE admin_id = '" . addslashes($admin->admin_id) . "'" . " AND admin_shortcut_url = '" . addslashes($shortcut_url) . "'"; $admin_shortcut_result = $db->query($query); if(!($admin_shortcut_result->count() > 0)) { $admin_shortcut_temp = new Tbl(); $admin_shortcut_temp->admin_id = $admin->admin_id; $admin_shortcut_temp->admin_shortcut_url = $shortcut_url; $admin_shortcut_temp->admin_shortcut_label = $shortcut_label; $options = array(); $options["table"] = "admin_shortcut"; $options["object"] = $admin_shortcut_temp; $db->put($options); $_SESSION["admin"]["messages"][] = "Shortcut successfully added."; redirect("image_library.htm"); } else { $_SESSION["admin"]["errors"][] = "The shortcut you attempted to add already exists for your account."; redirect("image_library.htm"); } // end if break; default: redirect($_SERVER["PHP_SELF"] . ((Str::has_value($_SERVER["QUERY_STRING"])) ? "?" . $_SERVER["QUERY_STRING"] : "")); } // end switch } // end if include("head.inc"); ?>

Image & File Library

Upload Files

">
Shortcuts:
Action:
Top Level"; } // end if foreach($crumbs as $index => $crumb) { if(!Str::has_value(trim($crumb))) { continue; } // end if $crumb_count++; if((max(count($crumbs) - 1, 0)) - $crumb_count > 0) { $crumb_link = (($crumb_count < count($crumbs)) ? " > " : "") . "" . $crumb . ""; echo $crumb_link; } else { echo (($crumb_count < count($crumbs)) ? " > " : "") . $crumb; } // end if } // end foreach ?>
$file) { $image_count++; $is_image = false; if(getimagesize($file_dir . $file)) { $is_image = true; list($width, $height, $type, $attr) = getimagesize($file_dir . $file); } // end if ?> 0) { ?> 0)) { echo "
No images are available in this directory
"; } // end if ?>
Action: