Répertoire de codes source
| Zend_Upload | |
|---|---|
|
déposé par poppy le 24/08/2007 nombre de visites : 3997 |
voila une petit classe pour uploader des fichiers sur le serveur par http. voila la source http://axel.2ate.net/update/contrib/zend/framework/Zend_Upload.zip touts les classes pour ZF http://axel.2ate.net/update/contrib/zend/framework/ ps: j'ai envoyer mes classes a Zend pour qu'il les ajouter au framework, en espérant qu'il valid ^^
|
<?php /** * Zend Framework * * LICENSE * * This source file is subject to the new BSD license that is bundled * with this package in the file LICENSE.txt. * It is also available through the world-wide-web at this URL: * http://framework.zend.com/license/new-bsd * If you did not receive a copy of the license and are unable to * obtain it through the world-wide-web, please send an email * to license@zend.com so we can send you a copy immediately. * * @category Zend * @package Zend_Upload * @copyright Copyright (c) 2005-2007 Axel ETCHEVERRY (http://axel.2ate.net) * @license http://framework.zend.com/license/new-bsd New BSD License * @author Axel ETCHEVERRY * @link http://axel.2ate.net * @email euskadi31[at]gmail[dot]com * @version 1.0 */ require_once 'Zend/Upload/Exception.php'; class Zend_Upload { /* * @var string */ protected $file; /* * @var string */ protected $path; /* * @var string */ protected $url; /* * @var string */ protected $extention; /* * @var string */ protected $name; /* * @var string */ protected $fileExtention; /* * @access public * @param string $file */ public function __construct($file) { $this->file = $_FILES[$file]; $this->extention = "png|jpg|jpeg|gif"; } /* * @access public * @param string $ext * @return Zend_Upload Provides fluent interface */ public function setExtention($ext = "png|jpg|jpeg|gif") { $this->extention = $ext; return $this; } /* * @access public * @param string $path * @return Zend_Upload Provides fluent interface */ public function setPath($path) { $this->path = $path; return $this; } /* * @access public * @param string $name * @return Zend_Upload Provides fluent interface */ public function setName($name) { $this->name = $name; return $this; } /* * @access public * @return Zend_Upload Provides fluent interface */ public function upload() { if(!empty($this->file['name'])) { $this->_extention($this->file['name']); if(!empty($this->name)) { $this->file['name'] = $this->name.".".$this->fileExtention; } $this->uri = $this->path . "/" . $this->file['name']; if(eregi("(".$this->extention.")", $this->file['name'])) { if(!@move_uploaded_file($this->file['tmp_name'], $this->uri)) { throw new Zend_Upload_Exception("Upload file failed !!!"); return $this; } @chmod($this->uri, 0644); return $this; }else{ throw new Zend_Upload_Exception("L'extention n'est pas valide !"); return $this; } }else{ throw new Zend_Upload_Exception("Merci de sélectionner un fichier"); return $this; } } /* * @access protected * @param string $filename */ protected function _extention($filename) { $ext = explode(".", $filename); $this->fileExtention = array_pop($ext); } /* * @access public * @return string */ public function getName() { return $this->file['name']; } /* * @access public * @return string */ public function getUri() { return $this->uri; } /* * @access public * @return string */ public function getPath() { return $this->path; } } ?> |
|

