НеУчаcтник+


Зарегистрирован: Mar 2002
Место проживания:
Публикаций: 270
Статус:  |
Не помню где я это нарыл и что переделал в этом скрипте, но все работает на нескольких серверах ...
Попробуй
Как сам наверное определил var $allowed_types и есть то что тебе нужно
PHP:
<?
class cupload {
var $the_file = "";
var $error = "";
var $my_max_file_size = "102400"; # in bytes
var $image_max_width = "300"; # in pixels
var $image_max_height = "300"; # in pixels
var $allow_list = false;
var $the_path = "/ где_ты_будешь_хранить_закач анные_файлы";
var $allowed_types = array("image/bmp","image/gif","image/pjpeg","image/jpeg");
var $registered_types = array(
"application/x-gzip-compressed" => ".tar.gz, .tgz",
"application/x-zip-compressed" => ".zip",
"application/x-tar" => ".tar",
"text/plain" => ".html, .php, .txt, .inc (etc)",
"image/bmp" => ".bmp, .ico",
"image/gif" => ".gif",
"image/pjpeg" => ".jpg, .jpeg",
"image/jpeg" => ".jpg, .jpeg",
"application/x-shockwave-flash" => ".swf",
"application/msword" => ".doc",
"application/vnd.ms-excel" => ".xls",
"application/octet-stream" => ".exe, .fla (etc)"
);
// the class constructor
function cupload() {
global $the_file_name, $the_file, $SERVER_NAME, $DOCUMENT_ROOT;
$this->error = $this->validate_upload($the_file);
if ($this->error) {
$this->form($this->error);
} else {
if (!@copy($the_file, $this->the_path . "/" . $the_file_name)) {
$this->form("\n<b>Something barfed, check the path to and ".
"the permissions for the upload directory</b>");
} else {
if ($this->allow_list) $this->list_files();
else echo "Your string is:<br><img src=\"http://".$SERVER_NAME.ereg_replace($DOCUMENT_ROOT,"",$this->the_path)."/".$the_file_name."\">";
$this->form();
}
}
}
// form upload creator
function form($error=false) {
global $PHP_SELF;
if ($this->error)
echo $this->error . "<br><br>";
echo"\n<form ENCTYPE=\"multipart/form-data\" action=\"" . $PHP_SELF . "\" method=\"post\">";
echo "\n<INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"" . $this->my_max_file_size . "\">";
echo "\n<INPUT TYPE=\"hidden\" name=\"task\" value=\"upload\">";
echo "\n<P>Upload a file";
echo "\n<BR>NOTE: max file size is " . ($this->my_max_file_size / 1024) . "KB";
echo "\n<br><INPUT NAME=\"the_file\" TYPE=\"file\" SIZE=\"35\">";
echo "\n<input type=\"submit\" Value=\"Upload\">";
echo "\n</form>";
}
function validate_upload($the_file) {
global $the_file_type;
$start_error = "\n<b>Help:</b>\n";
if (!isset($this->error)) $this->error="";
if ($the_file == "") {
$this->error .= "\n<li>You did not upload anything!</li>";
} else {
if (!@in_array($the_file_type,$this->allowed_types)){
$this->error .= "\n<br>The file that you uploaded was of a type that is?not allowed, you are only allowed to upload files of the type:\n<ul>";
while ($type = @current($this->allowed_types)) {
$this->error .= "\n<li>" . $this->registered_types[$type] . " (" . $type . ")</li>";
@next($this->allowed_types);
}
$this->error .= "\n</ul>";
}
if (ereg("image",$the_file_type) && (in_array($the_file_type, $this->allowed_types))) {
$size = @GetImageSize($the_file);
list($foo,$width,$bar,$height) = explode("\"",$size[3]);
if ($width > $this->image_max_width)$this->error .= "\n<br>Your image should be no wider than?$this->image_max_width Pixels</li>";
if ($height > $this->image_max_height) $this->error .= "\n<br>Your image should be no higher than $this->image_max_height Pixels</li>";
}
if ($this->error) {
$this->error = $start_error . $this->error . "\n</ul>";
return $this->error;
} else {
return false;
}
}
}
function list_files() {
$handle = dir($this->the_path);
echo "\n<b>Uploaded files:</b><br>";
while ($file = $handle->read()) {
if (($file != ".") && ($file != "..")) {
echo "\n" . $file . "<br>";
}
}
}
}// end class
?>
Сообщить модератору об этом сообщении | Предупреждение | IP: определен
|