wok-next view wikiss/stuff/plugins/wkp_Upload.php @ rev 10793

squid: use --with-logdir=, install errors templates, touch cache.log and chown -R in post_install (Thanks for the report Allan)
author Christophe Lincoln <pankso@slitaz.org>
date Thu Jun 02 17:33:12 2011 +0200 (2011-06-02)
parents
children 423d8ab737fc
line source
1 <?php # coding: utf-8
3 /** Transfert un fichier (images ...) dans pages/data
4 * Accès via : ?action=upload
5 */
6 class Upload
7 {
8 public $description = "Télécharge un fichier dans la base Wiki";
10 function template()
11 {
12 global $html;
14 $upload = "Chargement";
15 switch ($_GET["action"]) {
16 case "edit" :
17 $html = preg_replace("/HISTORY/",
18 "<a href=\"$urlbase?action=upload\">$upload</a> / HISTORY",
19 $html);
20 break;
21 case "upload" :
22 case "uploadfile" :
23 $html = preg_replace('/ \/ <a href.*recent.*<\/a>/', '', $html);
24 $html = preg_replace('/.*name="query".*/', '', $html);
25 break;
26 default:
27 return 1;
28 }
29 return 0;
30 }
32 function action($a)
33 {
34 global $plugins,$CONTENT,$HELP_BUTTON,$EDIT_BUTTON,$PAGE_TITLE,
35 $PAGE_TITLE_link,$editable;
37 $upload = "Chargement";
38 switch ($a) {
39 case "upload" :
40 $PAGE_TITLE_link = FALSE; // pas de lien sur le titre
41 $editable = FALSE; // non editable
42 $PAGE_TITLE = "$upload"; // titre de la page
43 $CONTENT = '
44 <form method="post" enctype="multipart/form-data" action="?action=uploadfile">
45 <input type="file" name="file" value="file"/>
46 <input type="submit"/>
47 </form>
48 ';
49 break;
50 case "uploadfile" :
51 @mkdir("pages/data");
52 $name = $_FILES["file"]["name"]; $n="";
53 if (is_file("pages/data/".$name)) $n=1;
54 while (is_file("pages/data/".$n.$name)) $n++;
55 move_uploaded_file($_FILES["file"]["tmp_name"], "pages/data/".$n.$name);
56 $url = "pages/data/".$n.$name;
57 $PAGE_TITLE_link = FALSE; // pas de lien sur le titre
58 $editable = FALSE; // non editable
59 $PAGE_TITLE = "$upload"; // titre de la page
60 $CONTENT = '<h1><a href="javascript:history.go(-2)">'.
61 $EDIT_BUTTON.'</a></h1>
62 <p>
63 Le fichier '.$_FILES["file"]["name"].' ('.$_FILES["file"]["size"].' octets, '.
64 $_FILES["file"]["type"].' est plac&eacute; en <a href="'.$url.'">'.
65 $url.'</a>.
66 </p>';
67 switch (substr($_FILES["file"]["type"],0,4)) {
68 case "imag":
69 $CONTENT .= '
70 <p>
71 Vous pouvez inc&eacute;rer cette image avec <b>['.$url.']</b> voir
72 <a href="?page='.$HELP_BUTTON.'">'.$HELP_BUTTON.'</a> pour plus de d&eacute;tails.
73 </p>
74 <img src="'.$url.'" alt="'.$url.'" />';
75 break;
76 }
77 break;
78 default:
79 return FALSE; // action non traitée
80 }
81 return TRUE;
82 } // action
83 }
85 ?>