Bulletproof image uploader setName() function seems broken

31 Views Asked by At

I'm using https://github.com/samayo/bulletproof to upload images in the version 5.0.1. and it seems that the setName() function doesn't seem to work properly.

When you use it like the given example from the "usage" section of the readme:

require_once  "path/to/bulletproof.php";

$image = new Bulletproof\Image($_FILES);
$image = setName("test"); //will fail

 if($image["pictures"]){

   $upload = $image->upload(); 

   if($upload){
     echo $upload->getPath();
   }else{
     echo $image->getError(); 
   }
 }

You might end up having a random alphanumeric filename even when you call setName().

To me it looks like setName() is called twice, once when you call it manually as in the given example above and from the bulletproof class itself through a function called constraintValidator() at the end of the file. In the second call the parameter u give it (in the example case "test") won't pass through.

So for those facing the same issue and don't have a solution yet: This is the workaraound I use until it might get fixed. Adding the name parameter to the second call:

$this->setName($this->name);

Hope this helps someone and saves some time.

Please correct me if I'm wrong with my assumption.

0

There are 0 best solutions below