action.php 865 B

12345678910111213141516171819202122232425262728293031
  1. <?php
  2. global $_,$conf;
  3. switch($_['action']){
  4. case 'fritzing_upload_resource':
  5. Action::write(function($_,&$response){
  6. global $myUser;
  7. $resource = Resource::getByid($_['id']);
  8. $sketch = Sketch::getById($resource->sketch);
  9. $ext = getExt($_FILES['file']['name']);
  10. if($myUser->id != $sketch->owner) throw new Exception("Seul le propriétaire du sketch peux faire ça");
  11. if($ext!='fzz') throw new Exception('Extensions autorisées .fzz');
  12. if($_FILES['file']['size']>ALLOWED_RESOURCE_SIZE) throw new Exception('Taille maximum autorisée '.ALLOWED_RESOURCE_SIZE.' o');
  13. $name = $resource->id.'.'.$ext;
  14. $path = SKETCH_PATH.$name;
  15. move_uploaded_file($_FILES['file']['tmp_name'], $path);
  16. $resource->content = $name;
  17. $resource->save();
  18. $response = array_merge(ResourceType::all($resource->type));
  19. });
  20. break;
  21. }
  22. ?>