0

Im trying to pass the verot image editing class to a custom class that I created, but it doesnt seem to work, it doesnt do anything when I try to run it. How do I pass the verot image class to my class?

//Edit.php
//Now I run my class
$process = new ProcessEventLogo();
$process->editEventLogo($event_id,$file_ext,$savepath,new upload(''));

Here is my custom class. I thought by running upload('') to this method, Im passing a copy of the verot upload class that I can access in my custom class method. But when I run it, it doesnt even get past the $mainimg->uploaded path. In fact $mainimg = $fileupload->upload($savefile); returns NULL when I var_dump it. What am I doing wrong?

class ProcessEventLogo {

    public function editEventLogo($eventid,$fext,$url,$savepath,$fileupload)
    {

        //We generate the file name to save this image to
        $savefile = $savepath .'event_' .$eventid .'.' .$fext;

        //We check to see if the event image is there
        $mainimg = $fileupload->upload($savefile);

        //We now resize the image
        if($mainimg->uploaded)
        {

            $mainimg->file_overwrite = TRUE;
            $mainimg->image_ratio_crop = TRUE;
            $mainimg->image_resize = TRUE;
            $mainimg->image_x = 50;
            $mainimg->image_y = 50;
            $mainimg->process($savefile);

            if($mainimg->processed)
            {
                echo $mainimg->error;

            }

        }

    }
John
  • 9,840
  • 26
  • 91
  • 137

2 Answers2

0

It appears this worked, can someone verify this is the proper way of doing this? So instead of this line:

//We check to see if the event image is there
$mainimg = $fileupload->upload($savefile);

This worked.

//We check to see if the event image is there
$mainimg = new $fileupload($savefile);
John
  • 9,840
  • 26
  • 91
  • 137
  • not really sure and maybe im wrong but it seems that if u pass first "new upload('')" in your function you create an instance of the class which try to upload a file that is not found, in this case '' (look into __construct of uploadclass "https://github.com/verot/class.upload.php/blob/master/src/class.upload.php") and in the second call "new $fileupload($savefile);" you create a new instance of it with a valid filename – enno.void Apr 11 '17 at 17:45
  • @mr.void Right, so how else would I pass this class to my custom class method? Just seems like this is the wrong way. – John Apr 11 '17 at 18:02
0

@mr.void Right, so how else would I pass this class to my custom class method? Just seems like this is the wrong way

I think writing a little Factory is the right way for this:

class uploadFac {

    public function getUploadInstance($file)
    {
        return new upload($file)
    }

}

And use it like this:

$uplFac = new uploadFac();
$process = new ProcessEventLogo();
$process->editEventLogo($event_id,$file_ext,$savepath,$uplFac);

and in the method:

    public function editEventLogo($eventid,$fext,$url,$savepath,$uplFac)
    {
        //We generate the file name to save this image to
        $savefile = $savepath .'event_' .$eventid .'.' .$fext;
        $mainimg = $uplFac->getUploadInstance($savefile);
enno.void
  • 6,242
  • 4
  • 25
  • 42