Do not uploading two file and more

Hi everyone!

Strange reaction on second file:

$path = Yii::app()->params['path']['projects']; //correct uploading folder path

    $file = new CUploadedFile($_FILES['file']['name'], $_FILES['file']['tmp_name'], $_FILES['file']['type'], $_FILES['file']['size'], $_FILES['file']['error']); //create file

    $filename = U::genName($file->getName()); //d3dd32928cc3_111.jpg

    $file->saveAs( $path . $filename ); // true

    $fileTh = new CUploadedFile($_FILES['file']['name'], $_FILES['file']['tmp_name'], $_FILES['file']['type'], $_FILES['file']['size'], $_FILES['file']['error']); //the same as the first variant

    $thumbName = U::genName($fileTh->getName()); //87d830c7e660_111.jpg 

    $fileTh->saveAs($path . $thumbName); // false оО why FALSE?    

Why false in second object?

See the docs.

Also, you seem to be overcomplicating the creation of the CUploadedFile object. You should be able to just do this:

$file = CUploadedFile::getInstanceByName('file');

As far as I can tell, this is what you need:

$path = Yii::app()->params['path']['projects'];

$file = CUploadedFile::getInstanceByName('file');

$fileName = U::genName($file->getName());

$thumbName = U::genName($file->getName());

$file->saveAs($path . $fileName, false);

$file->saveAs($path . $thumbName);

Although you’ll want to do some error checking.