Jump to content
pixAN

Class Uploader image dans un dossier

Recommended Posts

Bonjour,

Je suis entrain de faire des test avec la class uploader. pour cela j'ai crée un module : 

 

public function processFile()
{
       if(Tools::isSubmit('button_submit')){
          $file_img = Tools::getValue('fileupload');
          $_registration_allowed_extensions = array('txt','rtf','doc','docx','pdf','png','jpg');
          $uploader = new Uploader($file_img); 
          $uploader->setAcceptTypes($_registration_allowed_extensions) 
          ->setCheckFileSize(Uploader::DEFAULT_MAX_SIZE) 
          ->setSavePath(dirname(__FILE__)) 
          ->process(); 
        }

}

public function hookDisplayAdminOrder($params)
{

       $this->processFile();
       return $this->display(__FILE__, 'filetemplate.tpl');
}

et le fichier filetemplate.tpl :

 

<form action="" method="post">

<input type="file" name="fileupload" />
<button type="submit" name="button_sbmit" class="button btw btn-default button-medium">
            <span>Envoyer <i class="icon-chevron-right right"></i></span>
            </button>

</form>

Mais aucune image n'est enregistré dans mon module

 

Voici ce que j'ai si je fait un print_r de $uploader :

 

Uploader Object ( [_check_file_size:UploaderCore:private] => 1 [_accept_types:UploaderCore:private] => [_files:UploaderCore:private] => [_max_size:UploaderCore:private] => [_name:UploaderCore:private] => monimage.jpg [_save_path:UploaderCore:private] => [files] => Array ( ) )

 

Une idée du problème ?

 

Merci

Share this post


Link to post
Share on other sites

j'avais mal placé mon print_r, voila ce que j'ai :

 

Uploader Object ( [_check_file_size:UploaderCore:private] => 10485760 [_accept_types:UploaderCore:private] => Array ( [0] => txt [1] => rtf [2] => doc [3] => docx [4] => pdf [5] => png [6] => jpeg [7] => gif [8] => jpg ) [_files:UploaderCore:private] => [_max_size:UploaderCore:private] => [_name:UploaderCore:private] => monimage.jpg [_save_path:UploaderCore:private] => ../modules/monmodule [files] => Array ( ) )

 

Par contre je n'ai rien dans [files].

 

Est-ce que cela pourrait venir de la :

 

 

$uploader = new Uploader($file_img);

 

ou il attend un résultat entre guillemet comme : new Uploader('mon image.jpg' ) ?  dans ce cas comment ajouter les guillemets à la variable $file_img ?

 

 

Edited by pixAN
update (see edit history)

Share this post


Link to post
Share on other sites

non apparemment ce n'est pas cela car je viens de faire un test sans guillemet avec une image.

 

Des idées?

Share this post


Link to post
Share on other sites

J'avais mal placé mon print_r , j'ai ça du coup

 

Uploader Object ( [_check_file_size:UploaderCore:private] => 10485760 [_accept_types:UploaderCore:private] => Array ( [0] => txt [1] => rtf [2] => doc [3] => docx [4] => pdf [5] => png [6] => jpeg [7] => gif [8] => jpg ) [_files:UploaderCore:private] => [_max_size:UploaderCore:private] => 10485760 [_name:UploaderCore:private] => fileupload [_save_path:UploaderCore:private] => ../modules/monmodule [files] => Array ( ) )

Mais [files] est vide .

 

Des idées ?

 

Share this post


Link to post
Share on other sites

j'ai fait une première erreur :

 

public function processFile()
{
       if(Tools::isSubmit('button_submit')){
          
          $_registration_allowed_extensions = array('txt','rtf','doc','docx','pdf','png','jpg');
          $uploader = new Uploader('fileupload'); -> attribut name de l'input !
          $uploader->setAcceptTypes($_registration_allowed_extensions) 
          ->setCheckFileSize(Uploader::DEFAULT_MAX_SIZE) 
          ->setSavePath(dirname(__FILE__)) 
          ->process(); 
        }

}

j'avais mis la valeur de l'insu dans new Uploader , alors qu'il faut l'attribut name mais mon [files] est toujours vide ... 

Share this post


Link to post
Share on other sites

Resolu.

 

Il manquait simplement  enctype="multipart/form-data"  dans la balise form.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...

Important Information

Cookies ensure the smooth running of our services. Using these, you accept the use of cookies. Learn More