Visualizzazione dei risultati da 1 a 3 su 3

Discussione: [PHP] upload class

  1. #1

    [PHP] upload class

    ciao ragazzi è da ieri che sto scrivendo una classe per gli uploads solo che questa mi dà errore:
    il primo è che se lascio ilform vuoto mi dice estensione proibita,
    il secondo è che mi dice dimensione file superata!
    la classe è questa:
    Codice PHP:
    <?
    /*
    +------------------------------------------------------------------+
    |                                                                  |
    | ================================================================ |
    | Name: pwm_uploads v 1.1 beta                                     |
    | ================================================================ |
    | Author: Dimischiavone                                            |
    | ================================================================ |
    | Email: [email]webmaster@portalewebmasters.com[/email]                           |
    | ================================================================ |
    | Start Date: 04-11-20005 - 12:51 GMT                              |
    | ================================================================ |
    | End Date: ??unknown                                                |
    | ================================================================ |
    | Made in: Italy                                                   |
    | ================================================================ |
    | File id: upload.class                                            |
    | ================================================================ |
    | License type: This software is relased under the GNU License     |
    | you can modify and redistribute it under the terms of GNU        |
    | license! Important: you cannot remove the original copyright     |
    | if you'll do it you may be persecuted1                           |
    | If you retain this script is good put my banner in your site     |
    | you can find ite visiting my site [url]www.portalewebmasters.com[/url]!     |
    | Enjoy ;)                                                         |
    | ================================================================ |
    |                                                                  |
    +------------------------------------------------------------------+
    */
    //I write all in english to let all people know
    //An information before,i'm italian so if i'm not very clear in my speaking is for this reason! ;)
    //Another thing for not italian users: you can translate the template or the form
    //Because i enclose comments that translate italian parts to english i think it's so easy
    //Now we set that the class can't have directly accesses 
    if (!defined("pwm_uploads"))
    {
    die(
    "[b]<h3><center>You can't access this file directly!</h3></center>[/b]");
    }
    //Let's set global vars so they can work properly with previous versions of php
    if(!isset($_FILES)) $_FILES $HTTP_POST_FILES;
    if(!isset(
    $_SERVER)) $_SERVER $HTTP_SERVER_VARS;
    if(!isset(
    $_POST)) $HTTP_POST_VARS;
    if(!isset(
    $_GET)) $HTTP_GET_VARS;
    //Ok now let's build the class!
    class upload

    //start setting all vars i don't explain all functions and vars
    var $version "1.1 Beta";
    var 
    $author "Dimischiavone";
    //Set the directory of your Uploads you may create it before if you don't do this you may have see errors!
    var $up_dir 'uploads';
    //Put here the url of your site even if you use a webserver offline localhost! 
    var $site_url 'http://www.portalewebmasters.com';
    var 
    $upload_dir '$this->site_url/$this->up_dir';
    //variables of file: file temporary name so the name that the server
    //Assign to moved file and the second var contain the original name of the file
    //That the client upload
    //This array will contain the specifics of client input
    var $files = array('name' => '','tmp_name' => '','size' => '','extension' => '''name_changed' => '');
    //If you retain to use other file extension continue the array and delete the extension that you don't wanna use!
    var $allowed_extensions = array('jpeg','jpg','bmp','gif','png','zip','txt','rtf','rar','wav','mpeg','mpg','mp4','mp3','php','html','htm');
    //Set the max file size modify it if you retain one thing only about this you cannot use size bigger than that setted in the php.ini
    //For more information create a file php and get the phpinfo(); information! Default size 3 MB!
    var $file_max_size '3127728';
    //Var default value void we set it ahead
    var $file_dir '';
    //Ok let's start make functions first is the construct
    //So begin there i don't write comments because i suppose that at this
    //Point you can understand without me the functions because you know the variables we wrote before
    function upload()
    {
    $this->files['name'] = $_FILES['file']['name'];
    $this->files['tmp_name'] = $_FILES['file']['tmp_name'];
    $this->files['name_changed'] = $_POST['name'];
    if (
    $this->if_form_is_void() == FALSE)
    {
    die(
    'Errore: non hai riempito il form con nessun parametro!');
    }
    elseif (
    $this->check_if_file_exists() == TRUE)
    {
    die(
    'Il file che vorresti caricare è già presente sul nostro server!');
    }
    elseif (
    $this->validate_extension() == FALSE)
    {
    die(
    "L'estensione usata é proibita!");
    }
    elseif (
    $this->validate_size() == FALSE)
    {
    die(
    'Il file che stai cercando di caricare supera la dimensione limite di $this->max_file_size byte,oppure non hai selezionato il file da caricare!');
    }
    if (
    $this->files['name_changed'] == NULL)
    {
    $this->file_dir "$this->upload_dir/$this->files['name'].$this->file['extension']";
    $upload move_uploaded_file($this->files['tmp_name'], $file_dir);
    }
    else
    {
    $this->file_dir "$this->upload_dir/$this->files['name_changed'].$this->extension";
    $upload move_uploaded_file($this->files['tmp_name'], $file_dir);
    }
    }
    function 
    validate_size()
    {
    if ((
    $this->files['size'] == 0) or ($this->files['size'] > $this->max_file_size))
    {
    return 
    FALSE;
    }
    else
    {
    return 
    TRUE;
    }
    }
    function 
    validate_extension()
    {
    $this->files['extension'] = strtolower(end(explode('.'$_FILES['file']['name'])));
    if (
    in_array($this->files['extension'], $this->allowed_extensions) == FALSE)
    {
    return 
    FALSE;  
    }
    else
    {
    return 
    TRUE;  
    }
    }
    function 
    check_if_file_exists()
    {
    if (
    file_exists("$this->upload_dir/$this->files['name'].$this->extension") == FALSE or file_exists("$this->upload_dir/$this->files['name_changed'].$this->extension") == FALSE)
    {
    return 
    FALSE;
    }
    else
    {
    return 
    TRUE;
    }
    }
    function 
    if_form_is_void()
    {
    if (!isset(
    $_FILES['file']))
    {
    return 
    FALSE;
    }
    else
    {
    return 
    TRUE;
    }
    }
    //end of the class
    }
    ?>
    il file che usa la classe è questo:
    Codice PHP:
    <?
    define
    ("pwm_uploads"TRUE);
    include_once(
    "upload.class.php");
    $upload = new upload();
    $upload->upload();
    ?>
    ora se gentilmente qualcuno ha gli occhi più riposati dei miei mi potrebbe dire se c'è qualche errorino che non ho notato?grazie in anticipo!

  2. #2
    faccio un piccolo up!

  3. #3
    un'altro up è un giorno ceh cerco qualche risposta oviamente sto cercando di capire ceh sbaglio ma non so proprio cosa provo a riscrivere la classe!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.