upload multipli

dopo aver risolto problemi con l'inserimento dei file nel database ho bisogno di metterne più di uno alla volta  ;D come posso fare , sarebbe deprimente dover aggiornare i file di una cartella e upparli uno ad uno :D

 :bye:

inviato 10 anni fa
Andrea Turso
Andrea Turso
86
X 0 X
risposto 10 anni fa
Gianni Tomasicchio
X 0 X

Grazie gianni ho trovato l'errore che mi risolve i due topic :

UPLOAD[] mi sono dimenticato di usare come nome una matrice html , che idiota :buck:

 :bye:

risposto 10 anni fa
Andrea Turso
Andrea Turso
86
X 0 X

gianni sto utilizzando questo codice per uppare un singolo file :

<?php

      function UploadEntry($field,$pid){            

                     

                     /* Upload a file into database

                      * @author : trashofmasters <trashofmasters@gmail.com>

                      * @date   : 01 . 07 . 2006

                      * @copy   : (c) Revoke soft 2006

                      * @return : string

                      */

                           

                  $query   = "SELECT `mime` FROM `mimes`";

                  $exec    = mysql_query($query);

                  

                  while($mime = mysql_fetch_array($exec)){

                     foreach($mime as $format){

                        $mimes[] = $format;

                     }

                  }                         

                        /*

                         * extract mime types from database

                         * create mime array

                         */

                  $error = FALSE;

                  

                  do{

                     if(!isset($_FILES[$field])){

                        $error = 'The form was not completed';

                        break;

                     } else {

                        $FILE = $_FILES[$field];

                     }

                     

                        switch($FILE['error']) :

                        

                           case UPLOAD_ERR_INI_SIZE:

                              $error = 'the file dimensions are too expensive';

                              break 2;

                              

                           case UPLOAD_ERR_PARTIAL:

                              $error = 'Error during file uploading!Retry';

                              break 2;

                           

                           case UPLOAD_ERR_NO_FILE:

                              $error = 'No files to upload';

                              break 2;

                              

                           case UPLOAD_ERR_FORM_SIZE:

                              $error = 'the file dimensione are too expensive';

                              break 2;

                              

                           case UPLOAD_ERR_OK:

                              if($FILE['size'] > 50000){

                                 $error = "the file dimension are too expensive";

                              }

                              break 2;

                           

                           default:

                              $error = 'UNKNOWN ERROR!';

                           

                           endswitch;

                           

                           if(!in_array($FILE['type'],$mimes)){

                              $msg = 'File format not allowed';

                              break;

                           }

                        } while(0);

                        

                        if(!$error){

                        

                        $query = "INSERT INTO `files` (`name`,`mime`,`data`,`dateline`,`author`,`hash`,`pid`)"

                                       . "VALUES ("

                                       .  " '" . $FILE['name'] . "',"

                                       .  " '" . $FILE['type'] . "',"

                                       .  " '" . addslashes($data) . "', "

                                       .  " '" . time() . "', "

                                       .  " '" . $_COOKIE['RvK_UserID'] . "', "

                                       .  " '" . sha1($data) . "', "

                                       .  " '" . $pid . "')";

                                       

                        if(!mysql_query($query)){

                           $error = 'Error during file upload';

                        }

                        echo mysql_error();

                     }                                          

                                               

               }

?>

come posso rendere questa funzione adatta all'upload di file multipli??

devo inglobare il do --- while in un foreach() ??? cosa devo mettere nel foreach???

:bye:

risposto 10 anni fa
Andrea Turso
Andrea Turso
86
modificato 10 anni fa
X 0 X

La funzione UploadEntry agisce su un unico file, identificato dal nome del campo del form che lo contiene ($field)

Non ti conviene modificare la funzione bensì richiamarla più volte per ciascun file uppato.

Ogni file avrà ovviamente il suo nome del campo $field

 :bye:

risposto 10 anni fa
Gianni Tomasicchio
X 0 X

ah quindi non mi coviene rimodificare la funzione ( se provo ad uppare un file ... lo uppa ma non printa nessun errore . . . -.- )

cmq mi converrebbe fare una cosa del tipo

foreach ($_FILES['upload'] as $file){

 $rvk->uploadentry('upload',2);

}

:bye:

risposto 10 anni fa
Andrea Turso
Andrea Turso
86
X 0 X

EDIT del post prima : non printa errori : perchè non ci sono ... provato ora modificando qualcosa e li mostra :)

Gianni in questo modo

<?php

      function UploadEntry($field,$pid,$AUTH){            

                     

                     /* Upload a file into database

                      * @author : trashofmasters <trashofmasters@gmail.com>

                      * @date   : 01 . 07 . 2006

                      * @copy   : (c) Revoke soft 2006

                      * @return : string

                      */

                           

                  $query   = "SELECT `mime` FROM `mimes`";

                  $exec    = mysql_query($query);

                  

                  while($mime = mysql_fetch_array($exec)){

                  $i = 0;

                     foreach($mime as $format){

                     

                        if($i%2)

                           break;

                           /*

                            * Jump repeated array values

                            */

                                                      

                        $mimes[] = $format;

                        

                        $i++;

                     }

                  }                         

                        /*

                         * extract mime types from database

                         * create mime array

                         */

                         

                  unset($exec,$query);

                  

                  $err_msg = false;

               

                  do{

                  

                     if(!isset($_FILES[$field])){

                        echo $err_msg = 'The form was not completed';

                        break;

                     } else {

                        $FILE = $_FILES[$field];

                     }

                     

                        switch($_FILES[$field]['error']) :

                        

                           case UPLOAD_ERR_INI_SIZE:

                              $err_msg = 'the file dimensions are too expensive';

                              break 2;

                              /*

                               * File dimensions limit ( ini set ) error

                               */

                              

                           case UPLOAD_ERR_PARTIAL:

                              $err_msg = 'Error during file uploading!Retry';

                              break 2;

                              /*

                               * partial upload error

                               */

                           

                           case UPLOAD_ERR_NO_FILE:

                              $err_msg = 'No files to upload';

                              break 2;

                              /*

                               * no file error

                               */

                              

                           case UPLOAD_ERR_FORM_SIZE:

                              $err_msg = 'the file dimensione are too expensive';

                              break 2;

                              /*

                               * file dimensions limit ( $_POST set ) error

                               */

                              

                           case UPLOAD_ERR_OK:

                              if($_FILES[$field]['size'] > 500000){

                                 $err_msg = "the file dimension are too expensive";

                              }

                              /*

                               * check dimensions again

                               */

                              break 2;

                           

                           default:

                              $err_msg = 'UNKNOWN ERROR!';

                              /*

                               * unknown error

                               */

                           

                           endswitch;

                           

                           if(!in_array($_FILES[$field]['type'],$mimes)){

                              $err_msg = 'File format not allowed';

                              break;

                           }

                              /*

                               * check if the file format is allowed

                               */                               

                        } while(0);

                        

                        if(!$err_msg){

                        

                        $DATA  = file_get_contents($_FILES[$field]['tmp_name']); 

                        

                        $query = "INSERT INTO `files` (`name`,`mime`,`data`,`dateline`,`author`,`hash`,`pid`)"

                                       . "VALUES ("

                                       .  " '" . $_FILES[$field]['name'] . "',"

                                       .  " '" . $_FILES[$field]['type'] . "',"

                                       .  " '" . addslashes($DATA) . "', "

                                       .  " '" . time() . "', "

                                       .  " '" . $AUTH . "', "

                                       .  " '" . sha1($DATA) . "', "

                                       .  " '" . $pid . "')";

                                       

                        if(!mysql_query($query)){

                           $error = 'Error during file upload';

                        }

                        

                     } 

                     if($err_msg){

                        echo $err_msg;

                        print_r($mimes);

                     } else {

                        echo 'upload completed';

                     }                                       

                                               

               }

?>

mi da sempre formato non consentito e il print_r($_FILES) mi da un array multi dimensionale :

Array

(

    [upload] => Array

        (

            [name] => Array

                (

                    [0] => index.php

                )

            [type] => Array

                (

                    [0] => application/force-download

                )

            [tmp_name] => Array

                (

                    [0] => D:\WINDOWS\TEMP\php41.tmp

                )

            [error] => Array

                (

                    [0] => 0

                )

            [size] => Array

                (

                    [0] => 43

                )

        )

)

che cosa ho combinato???

:bye:

risposto 10 anni fa
Andrea Turso
Andrea Turso
86
modificato 10 anni fa
X 0 X

Ho fatto una piccola modifica alla funzione, per farla funzionare con l'upload multiplo:

<?php
function UploadEntry(&$file,$pid,$AUTH){

   /* Upload a file into database
   * @author : trashofmasters <trashofmasters@gmail.com>
   * @date   : 01 . 07 . 2006
   * @copy   : (c) Revoke soft 2006
   * @return : string
   */

   $query   = "SELECT `mime` FROM `mimes`";
   $exec    = mysql_query($query);

   while($mime = mysql_fetch_array($exec)){
      $i = 0;
      foreach($mime as $format){

         if($i%2)
         break;
         /*
         * Jump repeated array values
         */

         $mimes[] = $format;

         $i++;
      }
   }
   /*
   * extract mime types from database
   * create mime array
   */

   unset($exec,$query);

   $err_msg = false;

   do{

      if(!isset($file)){
         echo $err_msg = 'The form was not completed';
         break;
      }

      switch($file['error']) :

      case UPLOAD_ERR_INI_SIZE:
         $err_msg = 'the file dimensions are too expensive';
         break 2;
         /*
         * File dimensions limit ( ini set ) error
         */

      case UPLOAD_ERR_PARTIAL:
         $err_msg = 'Error during file uploading!Retry';
         break 2;
         /*
         * partial upload error
         */

      case UPLOAD_ERR_NO_FILE:
         $err_msg = 'No files to upload';
         break 2;
         /*
         * no file error
         */

      case UPLOAD_ERR_FORM_SIZE:
         $err_msg = 'the file dimensione are too expensive';
         break 2;
         /*
         * file dimensions limit ( $_POST set ) error
         */

      case UPLOAD_ERR_OK:
         if($file['size'] > 500000){
            $err_msg = "the file dimension are too expensive";
         }
         /*
         * check dimensions again
         */
         break 2;

      default:
         $err_msg = 'UNKNOWN ERROR!';
         /*
         * unknown error
         */

         endswitch;

         if(!in_array($file['type'],$mimes)){
            $err_msg = 'File format not allowed';
            break;
         }
         /*
         * check if the file format is allowed
         */
   } while(0);

   if(!$err_msg){

      $DATA  = file_get_contents($file['tmp_name']);

      $query = "INSERT INTO `files` (`name`,`mime`,`data`,`dateline`,`author`,`hash`,`pid`)"
      . "VALUES ("
      .  " '" . $file['name'] . "',"
      .  " '" . $file['type'] . "',"
      .  " '" . addslashes($DATA) . "', "
      .  " '" . time() . "', "
      .  " '" . $AUTH . "', "
      .  " '" . sha1($DATA) . "', "
      .  " '" . $pid . "')";

      if(!mysql_query($query)){
         $error = 'Error during file upload';
      }

   }
   if($err_msg){
      echo $err_msg;
      print_r($mimes);
   } else {
      echo 'upload completed';
   }

}
?>

in questo modo dovresti riuscire ad usare un ciclo del genere:

foreach ($_FILES['upload'] as $file){

 $rvk->uploadentry($file,2);

}

fammi sapere

 :bye:

risposto 10 anni fa
Gianni Tomasicchio
X 0 X

ho messo la funzione che mi hai dato te ma quando la richiamo da sola

$obj->UploadEntry('upload',2); mi da errore:

Fatal error: Cannot pass parameter 1 by reference in D:\Programmi\Apache Group\Apache2\htdocs\REVOKE\revokesoft\upload.php on line 13

mba!? che vuol dire?

:bye:

risposto 10 anni fa
Andrea Turso
Andrea Turso
86
X 0 X

Non devi più richiamarla in quel modo, ma così:

$obj->UploadEntry($_FILES['upload'],2);

questa modifica dovrebbe permettere l'upolad multiplo, in questo modo:

foreach ($_FILES['upload'] as $file){

 $rvk->uploadentry($file,2);

}

risposto 10 anni fa
Gianni Tomasicchio
X 0 X

Gianni mi porta subito all'errore Formato non permesso . . . secondo me perchè non può fare il confronto in_array dato che non so come mai mi diventa un array multidimensionale Array (     [upload] => Array         (             [name] => Array                 (                     [0] => index.php                 )

            [type] => Array                 (                     [0] => application/force-download                 )

            [tmp_name] => Array                 (                     [0] => D:\WINDOWS\TEMP\phpB3.tmp                 )

            [error] => Array                 (                     [0] => 0                 )

            [size] => Array                 (                     [0] => 43                 )

        )

)

sto per uscire matto . . .

EDIT : è multidimensionale : perchè ho usato[] nel nome del campo anche con solo un'upload ,,, mi vien da piangere ora :2funny:

risposto 10 anni fa
Andrea Turso
Andrea Turso
86
modificato 10 anni fa
X 0 X

uffa funziona ma inserisce il vuoto nel database . . . non so più che fare . . .

risposto 10 anni fa
Andrea Turso
Andrea Turso
86
modificato 10 anni fa
X 0 X

scusa se ti ho esasperato Gianni ma con gli array sono una cippa :2funny:

ho risolto :

<?php

      function UploadEntry(&$file,$pid,$AUTHOR,$j = 0){

      

         /* Upload a file into database

         * @author : trashofmasters <trashofmasters@gmail.com>

         * @date   : 01 . 07 . 2006

         * @copy   : (c) Revoke soft 2006

         * @return : string

         */

      

         $query   = "SELECT `mime` FROM `mimes`";

         $exec    = mysql_query($query);

      

         while($mime = mysql_fetch_array($exec)){

            $i = 0;

            foreach($mime as $format){

      

               if($i%2)

               break;

               /*

               * Jump repeated array values

               */

      

               $mimes[] = $format;

      

               $i++;

            }

         }

         /*

         * extract mime types from database

         * create mime array

         */

      

         unset($exec,$query);

      

         $err_msg = false;

         do{

      

            if(!isset($file)){

               echo $err_msg = 'The form was not completed';

               break;

            }

      

            switch($file['error'][$j]) :

      

            case UPLOAD_ERR_INI_SIZE:

               $err_msg = 'the file dimensions are too expensive';

               break 2;

               /*

               * File dimensions limit ( ini set ) error

               */

      

            case UPLOAD_ERR_PARTIAL:

               $err_msg = 'Error during file uploading!Retry';

               break 2;

               /*

               * partial upload error

               */

      

            case UPLOAD_ERR_NO_FILE:

               $err_msg = 'No files to upload';

               break 2;

               /*

               * no file error

               */

      

            case UPLOAD_ERR_FORM_SIZE:

               $err_msg = 'the file dimensione are too expensive';

               break 2;

               /*

               * file dimensions limit ( $_POST set ) error

               */

      

            case UPLOAD_ERR_OK:

               if($file['size'][$j] > 500000){

                  $err_msg = "the file dimension are too expensive";

               }

               /*

               * check dimensions again

               */

               break 2;

      

            default:

               $err_msg = 'UNKNOWN ERROR!';

               /*

               * unknown error

               */

      

               endswitch;

      

               if(!in_array($file['type'][$j],$mimes)){

                  $err_msg = 'File format not allowed';

                  break;

               }

               /*

               * check if the file format is allowed

               */

         } while(0);

      

         if(!$err_msg){

      

            $DATA  = file_get_contents($file['tmp_name'][$j]);

      

            $query = "INSERT INTO `files` (`name`,`mime`,`data`,`dateline`,`author`,`hash`,`pid`)"

            . "VALUES ("

            .  " '" . $file['name'][$j] . "',"

            .  " '" . $file['type'][$j]. "',"

            .  " '" . addslashes($DATA) . "', "

            .  " '" . time() . "', "

            .  " '" . $AUTHOR . "', "

            .  " '" . sha1($DATA) . "', "

            .  " '" . $pid . "')";

      

            if(!mysql_query($query)){

               $error = 'Error during file upload';

            }

      

         }

         if($err_msg){

            echo $err_msg;

            print_r($mimes);

         } else {

            echo 'upload completed';

         }

      

      }

?>

e la richiamo in questo modo :

<?php

$j = 0;

         foreach($_FILES['upload'] as $key => $value){

         //echo '<pre>';

         //print_r($value);

         

         $file[$key] = $value;

         //echo '</pre>';

            $rvk->UploadEntry($file,2,1,$j);

            $j++;

         }

?>

PS a che serve & prima della var nella lista degli argomenti?

ha solo il problema che . . . inserisce tutti i campi anche quelli vuoti nel database ... aiutami a risolvere

pls :)

ah poi se completo tutti e 4 i form con 4 file diversi li mette nel DB e aggiunge un record vuoto alla fine xD

CI RINUUNCCIO !!!! lol mi sa che mi conviene lasciar perdere questo schifo di do ... while e provare qualc'osaltro che funzioni . . .

:bye:

risposto 10 anni fa
Andrea Turso
Andrea Turso
86
modificato 10 anni fa
X 0 X

tutto funziona ... se usato correttamente  :P

così è più elegante:

<?php
$n = count($_FILES['upload'])
for ($i=0 ; $i < $n ; $i++)
{
   $rvk->UploadEntry($_FILES['upload'][$i],2,1,$i);
}
?>
risposto 10 anni fa
Gianni Tomasicchio
X 0 X

lol ecco perchè :) in pratica faceva l'upload anche dei campi vuoti !!! LOOOOOOOOOL scusami Gianni, non ci vedo più dalla fame ;D poi sto preparando le valigie asd

EDIT : <?php

function UploadEntry(&$file,$pid,$AUTHOR,$j){

         /* Upload a file into database

         * @author : trashofmasters <trashofmasters@gmail.com>

         * @date   : 01 . 07 . 2006

         * @copy   : (c) Revoke soft 2006

         * @return : string

         */

         $query   = "SELECT `mime` FROM `mimes`";

         $exec    = mysql_query($query);

         while($mime = mysql_fetch_array($exec)){

            $i = 0;

            foreach($mime as $format){

               if($i%2)

               break;

               /*

               * Jump repeated array values

               */

               $mimes[] = $format;

               $i++;

            }

         }

         /*

         * extract mime types from database

         * create mime array

         */

         unset($exec,$query);

         $err_msg = false;

         do{

            if(!isset($file)){

               echo $err_msg = 'The form was not completed';

               break;

            }

            switch($file['error'][$j]) :

            case UPLOAD_ERR_INI_SIZE:

               $err_msg = 'the file dimensions are too expensive';

               break 2;

               /*

               * File dimensions limit ( ini set ) error

               */

            case UPLOAD_ERR_PARTIAL:

               $err_msg = 'Error during file uploading!Retry';

               break 2;

               /*

               * partial upload error

               */

            case UPLOAD_ERR_NO_FILE:

               $err_msg = 'No files to upload';

               break 2;

               /*

               * no file error

               */

            case UPLOAD_ERR_FORM_SIZE:

               $err_msg = 'the file dimensione are too expensive';

               break 2;

               /*

               * file dimensions limit ( $_POST set ) error

               */

            case UPLOAD_ERR_OK:

               if($file['size'][$j] > 500000){

                  $err_msg = "the file dimension are too expensive";

               }

               /*

               * check dimensions again

               */

               break 2;

            default:

               $err_msg = 'UNKNOWN ERROR!';

               /*

               * unknown error

               */

               endswitch;

               if(!in_array($file['type'][$j],$mimese)){

                  $err_msg = 'File format not allowed';

                  break;

               }

               /*

               * check if the file format is allowed

               */

         } while(0);

         if(!$err_msg){

            $DATA  = file_get_contents($file['tmp_name'][$j]);

            $query = "INSERT INTO `files` (`name`,`mime`,`data`,`dateline`,`author`,`hash`,`pid`)"

            . "VALUES ("

            .  " '" . $file['name'][$j] . "',"

            .  " '" . $file['type'][$j]. "',"

            .  " '" . addslashes($DATA) . "', "

            .  " '" . time() . "', "

            .  " '" . $AUTHOR . "', "

            .  " '" . sha1($DATA) . "', "

            .  " '" . $pid . "')";

            if(!mysql_query($query)){

               $error = 'Error during file upload';

            }

         } else {

            echo $err_msg;

         }

      }?>

chiamata così :

<?php if(isset($_POST['Submit'])){

$n = count($_FILES['upload']);

   for ($i=0 ; $i < $n ; $i++) {

         $rvk->UploadEntry($_FILES['upload'][$i],2,1,$i);

   }

         

   

      }

?>

mi produce:

The form was not completedThe form was not completedThe form was not completedThe form was not completedThe form was not completedThe form was not completedThe form was not completedThe form was not completedThe form was not completedThe form was not completed

e non inserisce nulla nel db . . .  non sto ragionando più :D

:bye:

se non scrivo più ci rivediamo a settembre :) CIAO!

risposto 10 anni fa
Andrea Turso
Andrea Turso
86
modificato 10 anni fa
X 0 X

Credo che il problema sia nella funzione :| infatti anche se la chiama fuori da un ciclo . . . mi da due errori ??? questa è una delle cacate che si possono fare con php :)

come caspio posso fare ? cioè mi conviene tornare alla funzione vecchia , con 200 bug ed insicura ma funzionante o far andare questa che è leggermente più sicura ( con qualche bug in più :) ma da correggere)

:bye:

risposto 10 anni fa
Andrea Turso
Andrea Turso
86
X 0 X

Fammi un riepilogo della situazione: script usati, errori ricevuti.

risposto 10 anni fa
Gianni Tomasicchio
X 0 X

allora

$rvk->UploadEntry($_FILES['upload'][0],2,1);

con tutti e quattro i campi vuoti

ERRORE :

The form Was Not CompletedThe form Was Not Completed

funzione :

quella postata da te

risposto 10 anni fa
Andrea Turso
Andrea Turso
86
X 0 X
con tutti e quattro i campi vuoti

cioè il form di upload è lascato vuoto?

risposto 10 anni fa
Gianni Tomasicchio
X 0 X

si

lol !!!

risposto 10 anni fa
Andrea Turso
Andrea Turso
86
X 0 X

Gianni ho corretto la funzione ora uppa e distingue i file da non caricare

però non so come chiamarla in modo relativo ai campi senza che mi generi errori senza motivo ... il metodo proposto da te :

$n = count($_FILES['upload']['name']);

for ($i=0 ; $i < $n ; $i++){

   $rvk->UploadEntry($_FILES['upload'],2,1,$i);

}

e ho messo [upload][name] perche altrimenti mi contava solo i campi TYPE,NAME,TMP_NAME,ERROR ecc... allora era sempre 5

cmq come posso fare?

ciao! e grazie

:bye:

risposto 10 anni fa
Andrea Turso
Andrea Turso
86
X 0 X

Gianni mi aiuti solo a chiamare la funzione e fargli uppare tanti file quanti sono i campi?

:bye:

risposto 10 anni fa
Andrea Turso
Andrea Turso
86
X 0 X

Una cortesia: prova a mettere 2 file nel form, ad inviarlo ed ad eseguire un print_r($_FILE);

Riporta poi il risultato.

 :bye:

risposto 10 anni fa
Gianni Tomasicchio
X 0 X

certo lo faccio subito :)

Array

(

    [upload] => Array

        (

            [name] => Array

                (

                    [0] => 129944555_cb75263d8e_o.jpg

                    [1] => 129944647_2f53f51bbd_o.jpg

                    [2] => 

                    [3] => 

                    [4] => 

                )

            [type] => Array

                (

                    [0] => image/jpeg

                    [1] => image/jpeg

                    [2] => 

                    [3] => 

                    [4] => 

                )

            [tmp_name] => Array

                (

                    [0] => D:\WINDOWS\TEMP\php21.tmp

                    [1] => D:\WINDOWS\TEMP\php22.tmp

                    [2] => 

                    [3] => 

                    [4] => 

                )

            [error] => Array

                (

                    [0] => 0

                    [1] => 0

                    [2] => 4

                    [3] => 4

                    [4] => 4

                )

            [size] => Array

                (

                    [0] => 822426

                    [1] => 823324

                    [2] => 0

                    [3] => 0

                    [4] => 0

                )

        )

)
risposto 10 anni fa
Andrea Turso
Andrea Turso
86
X 0 X
<?php
// creo un collegamento all'array dei file
$link = &$_FILES['upload'];

$n = count($link['name']);
for ($i=0 ; $i < $n ; $i++)
{
   // se non c'è il nome allora non c'è il file
   if(!trim($link['name'][$i])) continue;
   
   // costruisco un finto array $_FILE,
   // simulando l'upload di un unico file
   $FILE = array();
   $FILE['name']     = $link['name'][$i];
   $FILE['type']     = $link['type'][$i];
   $FILE['tmp_name'] = $link['tmp_name'][$i];
   $FILE['error']    = $link['error'][$i];
   $FILE['size']     = $link['size'][$i];
   
   $rvk->UploadEntry($FILE,2,1,$i);
}
?>
<?php
function UploadEntry(&$file,$pid,$AUTHOR,$j)
{
   /* Upload a file into database
   * @author : trashofmasters <trashofmasters@gmail.com>
   * @date   : 01 . 07 . 2006
   * @copy   : (c) Revoke soft 2006
   * @return : string
   */

   $query   = "SELECT `mime` FROM `mimes`";
   $exec    = mysql_query($query);

   while($mime = mysql_fetch_array($exec)) {
      $i = 0;
      foreach($mime as $format){

         if($i%2)
         break;
         /*
         * Jump repeated array values
         */

         $mimes[] = $format;

         $i++;
      }
   }
   /*
   * extract mime types from database
   * create mime array
   */

   unset($exec,$query);

   $err_msg = false;



   switch($file['error']) {

      case UPLOAD_ERR_INI_SIZE:
         $err_msg = 'the file dimensions are too expensive';
         break;
         /*
         * File dimensions limit ( ini set ) error
         */

      case UPLOAD_ERR_PARTIAL:
         $err_msg = 'Error during file uploading!Retry';
         break;
         /*
         * partial upload error
         */

      case UPLOAD_ERR_NO_FILE:
         $err_msg = 'No files to upload';
         break;
         /*
         * no file error
         */

      case UPLOAD_ERR_FORM_SIZE:
         $err_msg = 'the file dimensione are too expensive';
         break;
         /*
         * file dimensions limit ( $_POST set ) error
         */

      case UPLOAD_ERR_OK:
         if($file['size'] > 500000){
            $err_msg = "the file dimension are too expensive";
         }
         /*
         * check dimensions again
         */
         break;

      default:
         $err_msg = 'UNKNOWN ERROR!';
         /*
         * unknown error
         */
   }

   if(!in_array($file['type'],$mimese)){
      $err_msg = 'File format not allowed';
   }
   /*
   * check if the file format is allowed
   */


   if(!$err_msg) {

      $DATA  = file_get_contents($file['tmp_name']);

      $query = "INSERT INTO `files` (`name`,`mime`,`data`,`dateline`,`author`,`hash`,`pid`)"
      . "VALUES ("
      .  " '" . $file['name'] . "',"
      .  " '" . $file['type']. "',"
      .  " '" . addslashes($DATA) . "', "
      .  " '" . time() . "', "
      .  " '" . $AUTHOR . "', "
      .  " '" . sha1($DATA) . "', "
      .  " '" . $pid . "')";

      if(!mysql_query($query)){
         $error = 'Error during file upload';
      }

   } else {
      echo $err_msg;
   }
}
?>

Provalo e fammi sapere.

 :bye:

risposto 10 anni fa
Gianni Tomasicchio
X 0 X
Effettua l'accesso o registrati per rispondere a questa domanda