开发者

Zend_Form_Element_File the move_uploaded_file function don't return anything

I am trying to upload a picture. I have Form_Zend and I use:

        $image = new Zend_Form_Element_File('image');

    $image->setLabel('Upload an avatar:')
            ->setMaxFileSize(8388608)
           // ->setDestination('./usersImages')
            ->setDescription('Click Browse and choose an image');
    $image->addValidator('Count', false, 1);
    $image->addValidator('Size', false, 8388608);
    $image->addValidator('Extension', false, 'jpg,jpeg,png,gif');

    $this->addElement($image, 'image');

My controller action code:

if ($form->image->isUploaded()) {
                            $values = $form->getValues();
                            $source = $form->image->getFileName();

                            $extention = substr($source, strrpos($source, '.', -1));

                            $date = date('mdYhisa', time());

                            $new_image_name = 'avatar_' . $date . '_' . $idUser . $extention;

    $destination = "C:\\xampp\\tmp\\Srututututut.png";

                            $image_saved = move_uploaded_file($source, $destination);

                            if ($image_saved) {

                                $data = array(
                                    'img' => $new_image_name,
                                );
                                $userDT->update($data, 'id=' . $idUser);
                            }
                        }
                    }

But this move_uploaded_file is not returning nothing :/ What I have done:

  1. Checked if the file is uploading - yes it is in: C:\xampp\htdocs\Story\public\usersImages (if I set destination in this form element) or C:\xampp\tmp (if I dont set it)

  2. I was wondering about access to this folders but if it save there this images I think it has rights but I set in the apache:

    <Directory "C:/xampp/htdocs/Story/public/usersImages"> Allow from All </Directory>

  3. I was even tried use this function only in C:\xampp\tmp folder:

    开发者_如何学运维$source: C:\xampp\tmp\database.png $destination: C:\xampp\tmp\Srututututut.png

And still nothing :/

Do You have any suggestions?


I think that the problem is with $source = $form->image->getFileName();. The reason is that it will return a name of the file uploaded rather than where it was uploaded to (i.e. its temporary localization).

Thus, I think your source should be as follows:

$fileInfo = $mainForm->image->getTransferAdapter()->getFileInfo();
$source   = $fileInfo['image']['tmp_name'];

// to check if the source really points to the uploaded file.
var_dump(file_exists($source));


Ok, I have no idea why this function is not working. I have changed my idea to set the $form->image destination first in the controller and then rename it and it is working. Thanks for help guys ;D

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜