[PLUGINS] +crayons
[lhc/web/clavette_www.git] / www / plugins / crayons / action / crayons_upload.php
1 <?php
2 /**
3 * Crayons
4 * plugin for spip
5 * (c) Fil, toggg 2006-2013
6 * licence GPL
7 */
8
9 if (!defined("_ECRIRE_INC_VERSION")) return;
10
11 /**
12 * Upload de documents
13 *
14 * Cette action recoit des fichiers ($_FILES)
15 * et les affecte a l'objet courant ;
16 * puis renvoie la liste des documents joints
17 */
18 function action_crayons_upload() {
19
20 $type = preg_replace('/\W+/', '', strval(_request('type')));
21 $id = intval(_request('id'));
22
23 // check securite :-)
24 include_spip('inc/autoriser');
25 if (!autoriser('joindredocument',$type,$id)) {
26 echo "Erreur: upload interdit";
27 return false;
28 }
29
30 // on n'accepte qu'un seul document à la fois, dans la variable 'upss'
31 if ($file = $_FILES['upss']
32 AND $file['error'] == 0) {
33
34 $source = $file['tmp_name']; # /tmp/php/phpxxx
35 $nom_envoye = $file['name']; # mon-image.jpg
36
37 include_spip('plugins/installer'); // spip_version_compare dans SPIP 3.x
38 include_spip('inc/plugin'); // spip_version_compare dans SPIP 2.x
39 if (function_exists(spip_version_compare)) { // gerer son absence dans les branche precedente a SPIP 2.x
40 if (spip_version_compare($GLOBALS['spip_version_branche'], '3.0.0alpha', '>='))
41 define('_SPIP3', true);
42 }
43 if (defined('_SPIP3')) {
44 include_spip('action/ajouter_documents');
45 $ajouter_un_document = charger_fonction('ajouter_un_document','action');
46 $id = $ajouter_un_document("new", $file, $type, $id, 'document');
47 } else {
48 include_spip('inc/ajouter_documents');
49 $id = ajouter_un_document($source, $nom_envoye, $type, $id, 'document', $id_document=0, $documents_actifs, $titrer=true);
50 }
51 }
52
53 if (!$id)
54 $erreur = "erreur !";
55
56 $a = recuperer_fond('modeles/uploader_item',array('id_document' => $id, 'erreur' => $erreur));
57
58 echo $a;
59 }
60
61 ?>