codigo:
Cita:
y el upload es:<?php
require("../upload.php");
$status = "";
$username = $_COOKIE['loggedin'];
if ($_POST["action"] == "upload") {
$fupload = new Upload();
$fupload->setPath("../$username/files");
$fupload->setFile("archivo");
$fupload->isImage(true);
$fupload->save();
$status = $fupload->message;
}
?>
require("../upload.php");
$status = "";
$username = $_COOKIE['loggedin'];
if ($_POST["action"] == "upload") {
$fupload = new Upload();
$fupload->setPath("../$username/files");
$fupload->setFile("archivo");
$fupload->isImage(true);
$fupload->save();
$status = $fupload->message;
}
?>
Cita:
Alguien me podria decir si puedo poner un limite a subir, y como.<?php
class Upload {
var $maxsize = 0;
var $message = "";
var $newfile = "";
var $newpath = "";
var $filesize = 0;
var $filetype = "";
var $filename = "";
var $filetemp;
var $fileexte;
var $allowed;
var $blocked;
var $isimage;
var $isupload;
function Upload() {
$this->allowed = array("image/bmp","image/gif","image/jpeg","image/pjpeg","image/png","image/x-png");
$this->blocked = array("php","phtml","php3","php4","php5","js","sht ml","pl","py");
$this->message = "";
$this->isupload = false;
}
function setFile($field) {
$this->filesize = $_FILES[$field]['size'];
$this->filename = $_FILES[$field]['name'];
$this->filetemp = $_FILES[$field]['tmp_name'];
$this->filetype = $_FILES[$field]['type'];
$this->fileexte = substr($this->filename, strrpos($this->filename, '.')+1);
$this->newfile = substr(md5(uniqid(rand())),0,8).".".$this->fileexte;
}
function setPath($value) {
$this->newpath = $value;
}
function setMaxSize($value) {
$this->maxsize = $value;
}
function isImage($value) {
$this->isimage = $value;
}
function save() {
if (is_uploaded_file($this->filetemp)) {
// comprobar si el archivo es válido
if ($this->filename == "") {
$this->message = "Archivo no valido";
$this->isupload = false;
return false;
}
// comprobar el tamaño máximo
if ($this->maxsize != 0) {
if ($this->filesize > $this->maxsize*1024) {
$this->message = "Tamaño excesivo del archivo";
$this->isupload = false;
return false;
}
}
// comprobar si es imagen
if ($this->isimage) {
// comprobar dimensiones
if (!getimagesize($this->filetemp)) {
$this->message = "Imagen de archivo no valida";
$this->isupload = false;
return false;
}
// comprobar el tipo de contenido
if (!in_array($this->filetype, $this->allowed)) {
$this->message = "Tipo de contenido no valido";
$this->isupload = false;
return false;
}
}
// comprobar si el archivo se permite
if (in_array($this->fileexte, $this->blocked)) {
$this->message = "Archivo no permitido - ".$this->fileexte;
$this->isupload = false;
return false;
}
if (move_uploaded_file($this->filetemp, $this->newpath."/".$this->newfile)) {
$this->message = "Archivo subido correctamente!";
$this->isupload = true;
return true;
} else {
$this->message = "El archivo no se ha subido por favor, inténtelo de nuevo";
$this->isupload = false;
return false;
}
} else {
$this->message = "El archivo no se ha subido por favor, inténtelo de nuevo";
$this->isupload = false;
return false;
}
}
}
?>
class Upload {
var $maxsize = 0;
var $message = "";
var $newfile = "";
var $newpath = "";
var $filesize = 0;
var $filetype = "";
var $filename = "";
var $filetemp;
var $fileexte;
var $allowed;
var $blocked;
var $isimage;
var $isupload;
function Upload() {
$this->allowed = array("image/bmp","image/gif","image/jpeg","image/pjpeg","image/png","image/x-png");
$this->blocked = array("php","phtml","php3","php4","php5","js","sht ml","pl","py");
$this->message = "";
$this->isupload = false;
}
function setFile($field) {
$this->filesize = $_FILES[$field]['size'];
$this->filename = $_FILES[$field]['name'];
$this->filetemp = $_FILES[$field]['tmp_name'];
$this->filetype = $_FILES[$field]['type'];
$this->fileexte = substr($this->filename, strrpos($this->filename, '.')+1);
$this->newfile = substr(md5(uniqid(rand())),0,8).".".$this->fileexte;
}
function setPath($value) {
$this->newpath = $value;
}
function setMaxSize($value) {
$this->maxsize = $value;
}
function isImage($value) {
$this->isimage = $value;
}
function save() {
if (is_uploaded_file($this->filetemp)) {
// comprobar si el archivo es válido
if ($this->filename == "") {
$this->message = "Archivo no valido";
$this->isupload = false;
return false;
}
// comprobar el tamaño máximo
if ($this->maxsize != 0) {
if ($this->filesize > $this->maxsize*1024) {
$this->message = "Tamaño excesivo del archivo";
$this->isupload = false;
return false;
}
}
// comprobar si es imagen
if ($this->isimage) {
// comprobar dimensiones
if (!getimagesize($this->filetemp)) {
$this->message = "Imagen de archivo no valida";
$this->isupload = false;
return false;
}
// comprobar el tipo de contenido
if (!in_array($this->filetype, $this->allowed)) {
$this->message = "Tipo de contenido no valido";
$this->isupload = false;
return false;
}
}
// comprobar si el archivo se permite
if (in_array($this->fileexte, $this->blocked)) {
$this->message = "Archivo no permitido - ".$this->fileexte;
$this->isupload = false;
return false;
}
if (move_uploaded_file($this->filetemp, $this->newpath."/".$this->newfile)) {
$this->message = "Archivo subido correctamente!";
$this->isupload = true;
return true;
} else {
$this->message = "El archivo no se ha subido por favor, inténtelo de nuevo";
$this->isupload = false;
return false;
}
} else {
$this->message = "El archivo no se ha subido por favor, inténtelo de nuevo";
$this->isupload = false;
return false;
}
}
}
?>
Gracias