For example upload photo on the server - for example in normal PHP in this tutorial: http://www.tizag.com/phpT/fileupload.php We have catching errors: if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "There was an error uploading the file, please try again!"; }
So in Symfony I shouldn't think about possible errors during upload and I should delete block try-catch ? On 4 Lis, 10:12, Thomas Rabaix <[email protected]> wrote: > Depends what you mean by file upload ... > > PHP does not manage the "input stream", all the work is done before by the > webserver, so you can't catch any error at this point. > > > > On Wed, Nov 4, 2009 at 8:10 AM, dziobacz <[email protected]> wrote: > > > I didn't find article about catching errors which can be during upload > > file in Symfony - can I do something like that below using try - > > catch ? Is it a good solution when something during file upload will > > go wrong ? > > > $unique_code = md5(uniqid(mt_rand())); > > $file = $this->form->getValue('photo'); > > $extension = $file->getExtension($file->getOriginalExtension()); > > $name_photo = $unique_code.$extension; > > > try > > { > > > $thumbnail1 = new sfThumbnail(700, 700, true, > > false); > > $thumbnail1->loadFile($file->getTempName()); > > $thumbnail1->save(sfConfig::get('sf_upload_dir'). > > DIRECTORY_SEPARATOR .$name_photo); > > > $record = new Photo(); > > $record->date_add = date("Y-m-d H:i:s"); > > $record->photo = $name_photo; > > $record->save(); > > } > > catch(Exception $e) > > { > > if > > (file_exists(sfConfig::get('sf_upload_dir').'/'.$name_photo)) > > unlink(sfConfig::get('sf_upload_dir').'/'.$name_photo); > > } > > -- > Thomas Rabaixhttp://rabaix.net --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "symfony users" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/symfony-users?hl=en -~----------~----~----~----~------~----~------~--~---
