Thanx-a-mil
negblo
Moderator: General Moderators
Code: Select all
<?php
/* DESCRIPTION
FILE_UPLOADER( long max_size , string accepted_types , int save_mode , string upload_path , array post_file )
max_size maximum file size allowed. 2MB is default
do not use quotes
accepted_types string of mime-types allowed (ie: image/jpeg,image/gif)
save_mode FILE_UPLOADER_OVERWRITE
no quotes overwrite feil if a file already exists in upload_path
FILE_UPLOADER_INCREMENT
if a file by the same name already exists in the
upload_path increment the file using _#
FILE_UPLOADER_PROTECT
do nothing if a file by the same name already exists
upload_path destination of file (relative paths only)
post_file array file field name (ie $userfile)
*/
define("FILE_UPLOADER_OVERWRITE", 1, 1);
define("FILE_UPLOADER_INCREMENT", 2, 1);
define("FILE_UPLOADER_PROTECT", 3, 1);
class FILE_UPLOADER {
var $accepted_types;
var $save_mode;
var $max_filesize;
var $errors;
var $upload_path;
var $new_filename;
var $tmp_filename;
var $file_extension;
var $new_file_path;
var $orginal_filename;
var $fileArray;
function set_max_filesize($max_size) { $this->max_filesize = $max_size; }
function set_accepted($accepted_types) { $this->accepted_types = $accepted_types; }
function set_savemode($save_mode) { $this->save_mode = $save_mode; }
function set_path($upload_path) { $this->upload_path = $upload_path; }
function FILE_UPLOADER ($max_size = 2097152, $accepted_types = "", $save_mode = UPLOADER_PROTECT, $upload_path = "", $file = "") {
$this->upload_path = $upload_path;
$this->save_mode = $save_mode;
$this->accepted_types = $accepted_types;
$this->max_filesize = $max_size;
$this->fileArray = $file;
}
function upload ($file = "") {
if ($file == "" ) {
$file = $this->fileArray;
}
if ($this->fileArray == "" ) {
$this->errors = 'No file was uploaded.';
return false;
}
if ($file['size'] == 0) {
$this->errors = 'File is larger than allowed MAX_FILE_SIZE';
return false;
}
$this->temp_filename = $file['tmp_name'];
$this->original_filename = $file['name'];
if ($this->accepted_types != "" && strstr($this->accepted_types, $file['type'] ) === false ) {
$this->errors = 'This file type ''' .$file['type']. ''' is not allowed. Allowed types are ' .$this->accepted_types. '.';
return false;
}
if ( $file['size'] > $this->max_filesize) {
$this->errors = 'Maximum file size of exceeded. File may be no larger than ' .($this->max_filesize / 1024). ' KB.';
return false;
}
$this->new_filename = ereg_replace("[^a-z0-9._]","", ereg_replace(" ", "_",
ereg_replace("%20","_", strtolower($this->original_filename) )));
$pos = strrpos($this->new_filename, ".");
$this->file_extension = substr( $this->new_filename, $pos, strlen($this->new_filename) - $pos);
$this->new_filename = substr($this->new_filename, 0 , $pos);
$copy = "";
switch($this->save_mode) {
case 1: // overwrite mode
$this->new_file_path = $this->upload_path . $this->new_filename . $this->file_extension;
break;
case 2: // create new file with incremental extention
$n = 1;
while( file_exists($this->upload_path . $this->new_filename . $copy . $this->file_extension) ) {
$copy = "_" . $n++;
}
$this->new_file_path = $this->upload_path . $this->new_filename . $copy . $this->file_extension;
break;
default: // do nothing if exists, highest protection
if( file_exists($this->upload_path . $this->new_filename . $this->file_extension) ) {
$this->errors = $this->errors . "File "" . $this->new_filename . $this->file_extension . "" already exists";
return false;
}
else {
$this->new_file_path = $this->upload_path . $this->new_filename . $this->file_extension;
}
break;
}
copy( $this->temp_filename, $this->new_file_path );
if (! file_exists( $this->new_file_path ) ) {
$this->errors = "Could not move file from temp directory to '". $this->upload_path ."'";
return false;
}
return $this->new_filename . $copy . $this->file_extension;
}
}
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<form enctype='multipart/form-data' action='' method='post'>
<input type='hidden' name='MAX_FILE_SIZE' value='300000'>
<input name='userfile' type='file'>
<input type='submit' value='Send'>
</form>
<?php
// this code processes the uploaded file
if ( isset($_FILES['userfile']) ) {
$uploader = new FILE_UPLOADER( $_POST['MAX_FILE_SIZE'], '', FILE_UPLOADER_INCREMENT, 'images/', $_FILES['userfile']);
if (! ($newfilename = $uploader->upload() ) ) {
echo 'ERROR: ' .$uploader->errors;
}
else {
echo 'Your file has been uploaded to ' .$uploader->upload_path . $newfilename;
}
}
?>
</body>
</html>Code: Select all
<?php
If ($DeptResult){
header("Location: http://www.myplace.com/admin/admin.php? did=".$Did."&cid=".$Cid."&pid=0&olddid=".$Did."&oldcid=".$Cid."&oldpid=0");
exit(); // put this here
}
?>negblo wrote: 2.) I need my login page to disappear after I login...(ie, i will be opening a new window and i don't want the login widow to be open in the background.
Code: Select all
<script>window.close();</script>