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