Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    May 2005
    Messaggi
    15

    [php] richiamare file esterno

    ciao a tutti!!

    Ho il seguente probelma:

    ho creato un file che chiamerò per semplicità A.php che al suo interno deve richimare un secondo file B.php per quattro volte.

    Il file B.php mi serve per caricare file in un DB mysql ed il mio scopo era fare in modo che A.php chiamasse 4 volte B.php così avrei avuto come risultato un upload multiplo.

    Ho provato ad inserire un ciclo for all'interno del file A.php per richiamare il file B.php ma non funziona, come devo fare perchè A chiami il file esterno B...suggerimenti?





    grazie mille

  2. #2
    Utente di HTML.it L'avatar di luke83
    Registrato dal
    Jul 2000
    Messaggi
    1,217
    magari postando il codice... assicurati di mettere le graffe se usi require o include

    Codice PHP:
    // Questo NON VA BENE e non funzionerà come desiderato.
    if ($condizione)
        include 
    $file;
    else
        include 
    $un_altro;


    // Questo è CORRETTO.
    if ($condizione) {
        include 
    $file;
    } else {
        include 
    $un_altro;

    ... direttamente dal manuale...
    :master:
    ..::Luca::..
    » "se nn riesci a venirene a capo.. usa il tasto INVIO" © 2005 Luke83
    » "letta la documentazione, spazio all'immaginazione.." © 2006 Luke83
    [frasi random] - [Lucopedia] - [laFetta]

  3. #3
    Utente di HTML.it
    Registrato dal
    May 2005
    Messaggi
    15
    primo file

    Codice PHP:


    $files 
    = array ('upload66.php''upload66.php''upload66.php');
    for (
    $i 0$i count($files); $i++) {
      include 
    $files[$i];


    secondo file

    Codice PHP:

    $my_max_file_size     
    "307200"# in bytes
    $image_max_width    "400";
    $image_max_height    "500";

    $registered_types = array(
        
    "image/bmp"                 => ".bmp, .ico",
        
    "image/gif"                 => ".gif",
        
    "image/pjpeg"                => ".jpg, .jpeg",
        
    "image/jpeg"                => ".jpg, .jpeg",
        
    "image/png"                => ".png",
        
    "image/x-png"              => ".png"
        
    "application/x-shockwave-flash"     => ".swf",
        
    "application/msword"            => ".doc",
        
    "application/vnd.ms-excel"        => ".xls",
        
    "application/octet-stream"        => ".exe, .fla"
    );  # these are only a few examples, you can find many more!

    $allowed_types = array("image/gif","image/png","image/x-png","image/pjpeg","image/jpeg","image/bmp","application/x-shockwave-flash");
    //end global variables

    function dbconnect() {
         
    mysql_connect('');
        @
    mysql_select_db("") or die ("Unable to select database");
    }


    function 
    form($error=false) {

    global 
    $PHP_SELF$my_max_file_size$image_max_width$image_max_height;
    echo
    "<html><head><title>Uploading Files</title>
    <meta http-equiv=\"Content-Type\" content=\"text/html; charset=iso-8859-1\"></head>
    <body bgcolor=\"#EAEAEA\">"
    ;
        if (
    $error) print $error "

    "
    ;
        echo 
    "\n<form ENCTYPE=\"multipart/form-data\"  action=\"upload66.php\" method=\"post\">";
        echo 
    "\n

    <CENTER><h2>[b]Upload Files[/b]</center></h2>"
    ;
        echo 
    "\n<INPUT TYPE=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"" $my_max_file_size "\">";
        echo 
    "\n<INPUT TYPE=\"hidden\" name=\"task\" value=\"upload\">";
        echo 
    "\n
    [b]File1[/b]: <INPUT NAME=\"thefile\" TYPE=\"file\" SIZE=\"35\">
    "
    ;
        echo 
    "\n
    dimensione massima: " 
    . ($my_max_file_size 1024) . "KB - ".$image_max_width."x".$image_max_height." pixel";

        echo 
    "\n
    <input type=\"submit\" Value=\"Invia\" name=\"send\">"
    ;
        echo 
    "\n</form>";

    echo
    "</body></html>";
    # END form


    function validate_upload($thefile) {

    global 
    $my_max_file_size$image_max_width$image_max_height$allowed_types$thefile_type$registered_types$g_height$g_width$thefile_name;
        
        
    $start_error "\n[b]Si sono verificati i seguenti errori:[/b]\n<ul>";
        
        if (
    $thefile == "none") {
                
    $error .= "\n[*]Nessun file selezionato";
        } else {         
            if (!
    in_array($thefile_type$allowed_types)) {
                
    $error .= "\n[*]Il file non appartiene a queste tipologie:
                            
    \n<ul>"
    ;
                while (
    $type current($allowed_types)) {
                    
    $error .= "\n[*]" $registered_types[$type] . " (" $type ")";
                    
    next($allowed_types);
                }
                
    $error .= "\n[/list]";
            }
        
            if (
    ereg("image"$thefile_type) && in_array($thefile_type$allowed_types)) {
            
                
    $size GetImageSize($thefile);
                list(
    $foo,$width,$bar,$height) = explode("\"",$size[3]);
                
    $g_width=$width;

                if (
    $width $image_max_width) {
                    
    $error .= "\n[*]La larghezza dell'immagine non deve superare " $image_max_width " pixel";
                }
                
    $g_height=$height;
                if (
    $height $image_max_height) {
                    
    $error .= "\n[*]L'altezza dell'immagine non deve superare " $image_max_height " pixels";
                }
            }
            if (
    ereg("flash"$thefile_type) && in_array($thefile_type$allowed_types)) {
                
    $size GetImageSize($thefile);
                list(
    $foo,$width,$bar,$height) = explode("\"",$size[3]);
                
    $g_width=$width;
                
    $g_height=$height;
                if ((
    $width $image_max_width) || ($height $image_max_height)) {
                    if (
    $width >= $height) {
                        
    $g_width=$image_max_width;
                        
    $g_height=intval($height*$image_max_width/$width);
                    }
                    else {
                        
    $g_height=$image_max_height;
                        
    $g_width=intval($width*$image_max_height/$height);
                    }
                }
            }
            
            if (
    $error) {
                
    $error $start_error $error "\n[/list]";
                return 
    $error;
            } else {
                return 
    false;
            }
        }
    # END validate_upload



    function upload($thefile) {

    global 
    $thefile_name$thefile_type$thefile_size$g_width$g_height;
        
        
    $error validate_upload($thefile);
        if (
    $error) {
            
    form($error);
        } else { 
             
    $fp=@fopen($thefile"r");
             if (
    $fp) {
                 
    $data addslashes(fread($fpfilesize($thefile)));
                 
    $result=mysql_query("INSERT INTO db VALUES ('NULL', '$data','$thefile_name','$thefile_size','$thefile_type', '$g_width', '$g_height')");
                 
    fclose($fp);
                 
                 if (!
    $result) { echo mysql_errno(). ": ".mysql_error(). "
    "
    ; exit();}
                 else {
                     
    Header("Location: uploadprova.php");
                    
                 }
             } else {
                 echo
    "Il file selezionato non &egrave; valido, probabilmente &egrave; vuoto";
                 
    fclose($fp);
             }
        }
    # END upload






    dbconnect();

    switch(
    $task) {
        
        case 
    'upload':
            
    upload($thefile);
            break;
        
        default:
            
    form($error);



    spero possite aiutarmi

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.