suchen
Heimphp教程php手册仿开源中国,分享代码时候的多文件上传

仿开源中国,分享代码时候的多文件上传

Jun 06, 2016 pm 07:32 PM
上传中国代码分享开源文件Autor sensationeller Schlagzeilen

有点标题党,不过确实是一个不错的多文件上传类。简洁实用。 这个类可以用来处理表单上传多个文件。 这个类可以检查文件是否不为空,也没有超过给定的大小限制。 它也可以检查文件类型对允许和拒绝的文件类型列表。 该类还可以通过用下划线代替空格使最终的文

有点标题党,不过确实是一个不错的多文件上传类。简洁实用。
这个类可以用来处理表单上传多个文件。

这个类可以检查文件是否不为空,也没有超过给定的大小限制。

它也可以检查文件类型对允许和拒绝的文件类型列表。

该类还可以通过用下划线代替空格使最终的文件名更安全。

如果在上传文件时出现错误,类抛出一个异常对象,该对象提供有关错误代码和说明错误消息的信息。
代码珠玑:http://www.codepearl.com/files/194.html

源码与演示:源码出处 演示出处

仿开源中国,分享代码时候的多文件上传 仿开源中国,分享代码时候的多文件上传
<?php
//http://www.codepearl.com
$action = isset($_GET['action'])?$_GET['action']:"";
require_once('main.class.php');

$auc = new auc();

if ($action == 'uploadfile') {
	$auc = new auc();
	//Comment: $auc->upload_dir("directory name", "create dir if it does not exist, false by default or true");
	//$auc->upload_dir("/path/to/uploads/folder/with/trailing/slash/", false);
	//Comment: $auc->make_safe = true || false (default); make the file name safe
	//$auc->make_safe = true;
	//Comment: $auc->max_file_size = size in bytes (1MB default) || false; set max file size in bytes or false not to check size
	//$auc->max_file_size = 1048576;
	//Comment: $auc->overwrite = true || false (default); overwrite if file exists
	//$auc->overwrite = true;
	//Comment: $auc->check_file_type = false (default) || allowed || denied; 
	//$auc->check_file_type = 'allowed';	
	$result = $auc->upload("file");
	if (is_array($result)) {
		echo 'Something Went Wrong';
		echo '<pre class="brush:php;toolbar:false">';
		var_dump($result);
		echo '
'; } else { echo 'All OK'; } } else { ?> Upload Class - Demo


<?php
//http://www.codepearl.com
class auc {
	public $errors = array(); //array used to store any errors that occur.
	public $upload_dir = ''; //the upload_dir being used by the script
	public $make_safe = false; //default don't modify the file name to safe version
	public $max_file_size = 1048576; //Max File Size in Bytes, 1MB
	public $overwrite = false; //default don't overwrite files that already exsist
	public $check_file_type = false; //don't check for file type by default but can check for allowed and denied files.
	public $allowed_mime_types = array('image/jpeg', 'image/png', 'image/gif', 'image/tiff'); //array of allowed mime types used when check_file_type is set to allowed
	public $denied_mime_types = array('application/x-php', 'text/html'); //array of denied mime types used when check_file_type is set to denied
	
	/**
	 * Check if the upload dir is valid, if it is not valid attempt to make the dir, if dir is succesfully created chmod it to 0777. 
	 * If any elments fail return false else set upload_dir and return true.
	 * @param string $dir
	 * @param boolean $mkdir
	 * @return true or false
	 */
	public function upload_dir($dir, $mkdir = false) {
		$errors =& $this->errors;
		$status = true;
		
		if (!is_dir($dir)) {
			if ($mkdir) {
				if (!mkdir($dir)) {
					$status = false;
				} else {
					if (!chmod($dir, 0777)) $status = false;
				}
			} else {
				$status = false;
			}
		}
		
		if ($status) {
			$this->upload_dir = $dir;
			return true;
		} else {
			$errors['general'][] = 'Upload Dir is Not Valid and/or a dir could not be created/chmod.';
			return false;
		}
	}
	
	/**
	 * check that the upload dir is valid and that it is writeable
	 *
	 * @param string $dir
	 * @return true or false
	 */
	public function check_dir($dir) {
		if (!is_dir($dir) || !is_writable($dir)) return false;
		
		return true;
	}
	

	/**
	 * make the uploaded file name safe
	 *
	 * @param string $file_name
	 * @return safe file name
	 */
	public function make_safe($file_name) {
		return str_replace(' ', '_', $file_name);
	}
		
	/**
	 * Check the Attemted Uploads for errors etc if everything goes good move the file, to the upload_dir.
	 *
	 * @param array $object
	 * @return unknown
	 */
	public function upload($object) {
		$errors =& $this->errors;
		
		if (empty($errors['general'])) {
			if (empty($this->upload_dir)) $this->upload_dir = dirname(__FILE__).'/'; //if no default upload_dir has been specified used the current dir.
					
			if ($this->check_dir($this->upload_dir)) {
				$files = $_FILES[$object];
				$count = count($files['name']) - 1;
				
				echo '<pre class="brush:php;toolbar:false">';
				var_dump($files);
				echo '
'; for ($current = 0; $current max_file_size) { if ($files['size'][$current] >= $this->max_file_size) throw new TrigerErrorException($files['name'][$current].' exceeds defined max_file_size', $files['name'][$current]); } if ($this->check_file_type == 'allowed' && !in_array($files['type'][$current], $this->allowed_mime_types)) { throw new TrigerErrorException($files['name'][$current].' is not an allowed type', $files['name'][$current]); } elseif ($this->check_file_type == 'denied' && in_array($files['type'][$current], $this->denied_mime_types)) { throw new TrigerErrorException($files['name'][$current].' is a denied type', $files['name'][$current]); } //if make_safe is true call make safe function if ($this->make_safe) $files['name'][$current] = $this->make_safe($files['name'][$current]); //if overwrite is false and the file exists error if (!$this->overwrite && file_exists($this->upload_dir.$files['name'][$current])) throw new TrigerErrorException($files['name'][$current].' already exsists', $files['name'][$current]); //move the uploaded file, error if anything goes wrong. if (!move_uploaded_file($files['tmp_name'][$current], $this->upload_dir.$files['name'][$current])) throw new TrigerErrorException($files['name'][$current].' could not be moved', $files['name'][$current]); } catch (TrigerErrorException $e) { $errors[$files['name'][$current]][] = $e->Message(); } } if (empty($errors)) { //return true if there where no errors return true; } else { //return the errors array if there where any errros return $errors; } } else { //return false as dir is not valid $errors['general'][] = "The Specified Dir is Not Valid or is Not Writeable"; return false; } } } } /** * Handle the Exceptions trigered by errors within upload code. * */ class TrigerErrorException extends Exception { protected $file = ""; public function __construct($message, $file = "", $code = 0) { $this->file = $file; parent::__construct($message, $code); } public function Message() { return "{$this->message}"; } } ?>
Stellungnahme
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn

Heiße KI -Werkzeuge

Undresser.AI Undress

Undresser.AI Undress

KI-gestützte App zum Erstellen realistischer Aktfotos

AI Clothes Remover

AI Clothes Remover

Online-KI-Tool zum Entfernen von Kleidung aus Fotos.

Undress AI Tool

Undress AI Tool

Ausziehbilder kostenlos

Clothoff.io

Clothoff.io

KI-Kleiderentferner

AI Hentai Generator

AI Hentai Generator

Erstellen Sie kostenlos Ai Hentai.

Heißer Artikel

R.E.P.O. Energiekristalle erklärten und was sie tun (gelber Kristall)
3 Wochen vorBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Beste grafische Einstellungen
3 Wochen vorBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. So reparieren Sie Audio, wenn Sie niemanden hören können
3 Wochen vorBy尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: Wie man alles in Myrise freischaltet
3 Wochen vorBy尊渡假赌尊渡假赌尊渡假赌

Heiße Werkzeuge

Herunterladen der Mac-Version des Atom-Editors

Herunterladen der Mac-Version des Atom-Editors

Der beliebteste Open-Source-Editor

SecLists

SecLists

SecLists ist der ultimative Begleiter für Sicherheitstester. Dabei handelt es sich um eine Sammlung verschiedener Arten von Listen, die häufig bei Sicherheitsbewertungen verwendet werden, an einem Ort. SecLists trägt dazu bei, Sicherheitstests effizienter und produktiver zu gestalten, indem es bequem alle Listen bereitstellt, die ein Sicherheitstester benötigen könnte. Zu den Listentypen gehören Benutzernamen, Passwörter, URLs, Fuzzing-Payloads, Muster für vertrauliche Daten, Web-Shells und mehr. Der Tester kann dieses Repository einfach auf einen neuen Testcomputer übertragen und hat dann Zugriff auf alle Arten von Listen, die er benötigt.

DVWA

DVWA

Damn Vulnerable Web App (DVWA) ist eine PHP/MySQL-Webanwendung, die sehr anfällig ist. Seine Hauptziele bestehen darin, Sicherheitsexperten dabei zu helfen, ihre Fähigkeiten und Tools in einem rechtlichen Umfeld zu testen, Webentwicklern dabei zu helfen, den Prozess der Sicherung von Webanwendungen besser zu verstehen, und Lehrern/Schülern dabei zu helfen, in einer Unterrichtsumgebung Webanwendungen zu lehren/lernen Sicherheit. Das Ziel von DVWA besteht darin, einige der häufigsten Web-Schwachstellen über eine einfache und unkomplizierte Benutzeroberfläche mit unterschiedlichen Schwierigkeitsgraden zu üben. Bitte beachten Sie, dass diese Software

SublimeText3 Linux neue Version

SublimeText3 Linux neue Version

SublimeText3 Linux neueste Version

EditPlus chinesische Crack-Version

EditPlus chinesische Crack-Version

Geringe Größe, Syntaxhervorhebung, unterstützt keine Code-Eingabeaufforderungsfunktion