wok-current view wikiss/stuff/plugins/wkp_Upload.php @ rev 13288
memtest: lzma compression (again)
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Sun Aug 26 00:28:25 2012 +0200 (2012-08-26) |
parents | 423d8ab737fc |
children |
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 <table>
48 ';
49 if ($handle = @opendir("pages/data")) {
50 while(($item = readdir($handle)) !== false) {
51 if ($item == '..' || $item == '.') continue;
52 $CONTENT .= '<tr><td><input type=checkbox ';
53 exec('grep -qs "pages/data/'.$item.'" pages/*.txt', $tmp, $ret);
54 if ($ret == 0) $CONTENT .= 'checked=checked ';
55 $CONTENT .= 'disabled=disabled /><a href="pages/data/'.
56 $item.'">'.$item.'</a></td></tr>';
57 }
58 }
59 $CONTENT .= '
60 </table>
61 </form>
62 ';
63 break;
64 case "uploadfile" :
65 @mkdir("pages/data");
66 $name = $_FILES["file"]["name"]; $n="";
67 if (is_file("pages/data/".$name)) $n=1;
68 while (is_file("pages/data/".$n.$name)) $n++;
69 move_uploaded_file($_FILES["file"]["tmp_name"], "pages/data/".$n.$name);
70 $url = "pages/data/".$n.$name;
71 $PAGE_TITLE_link = FALSE; // pas de lien sur le titre
72 $editable = FALSE; // non editable
73 $PAGE_TITLE = "$upload"; // titre de la page
74 $CONTENT = '<h1><a href="javascript:history.go(-2)">'.
75 $EDIT_BUTTON.'</a></h1>
76 <p>
77 Le fichier '.$_FILES["file"]["name"].' ('.$_FILES["file"]["size"].' octets, '.
78 $_FILES["file"]["type"].' est placé en <a href="'.$url.'">'.
79 $url.'</a>.
80 </p>';
81 switch (substr($_FILES["file"]["type"],0,4)) {
82 case "imag":
83 $CONTENT .= '
84 <p>
85 Vous pouvez incérer cette image avec <b>['.$url.']</b> voir
86 <a href="?page='.$HELP_BUTTON.'">'.$HELP_BUTTON.'</a> pour plus de détails.
87 </p>
88 <img src="'.$url.'" alt="'.$url.'" />';
89 break;
90 }
91 break;
92 default:
93 return FALSE; // action non traitée
94 }
95 return TRUE;
96 } // action
98 function formatEnd()
99 {
100 global $CONTENT;
101 $CONTENT = preg_replace('#\[(.*)|(pages/.*)\]#','<a href="$1">$2</a>',$CONTENT);
102 $CONTENT = preg_replace('#\[(pages/.*)\]#','<a href="$1">$1</a>',$CONTENT);
103 }
104 }
106 ?>