root / src / raw_dir.MVC.php @ a9b72d88
Historique | Voir | Annoter | Télécharger (3,2 ko)
1 | d072e29c | Florent Chuffart | <?php
|
---|---|---|---|
2 | d072e29c | Florent Chuffart | $q = "SELECT * FROM $this->tb WHERE `$this->key`='$this->rec'"; |
3 | d072e29c | Florent Chuffart | // echo "$q";
|
4 | d072e29c | Florent Chuffart | // echo "<pre>";
|
5 | d072e29c | Florent Chuffart | // print_r($this);
|
6 | d072e29c | Florent Chuffart | // echo "</pre>";
|
7 | d072e29c | Florent Chuffart | $all = $this->myQuery($q); |
8 | d072e29c | Florent Chuffart | $current_object = mysql_fetch_object($all); |
9 | d072e29c | Florent Chuffart | |
10 | 0ce29891 | Florent Chuffart | if ($_FILES["userfile"]["error"]) { |
11 | 0ce29891 | Florent Chuffart | exit("ERROR, your file is probably too big, maximum upload file size is " . ini_get('upload_max_filesize') . ". <br/><a href='".$_SERVER["HTTP_REFERER"]."'>Back</a>"); |
12 | 0ce29891 | Florent Chuffart | } |
13 | 0ce29891 | Florent Chuffart | |
14 | 0ce29891 | Florent Chuffart | |
15 | d072e29c | Florent Chuffart | if ($current_object) { |
16 | d072e29c | Florent Chuffart | $current_class_raw_dir = "raw_dirs/$this->tb"; |
17 | d072e29c | Florent Chuffart | $current_entry_raw_dir = "$current_class_raw_dir/$this->rec/"; |
18 | d072e29c | Florent Chuffart | if ($_REQUEST["action"] == "ADD_RAW_FILE") { |
19 | d072e29c | Florent Chuffart | if (!file_exists($current_class_raw_dir)) { |
20 | d072e29c | Florent Chuffart | mkdir($current_class_raw_dir); |
21 | d072e29c | Florent Chuffart | } |
22 | d072e29c | Florent Chuffart | $userfile = $_FILES["userfile"]["tmp_name"]; |
23 | d072e29c | Florent Chuffart | $userfile_name = $_FILES["userfile"]["name"]; |
24 | d072e29c | Florent Chuffart | $ext = strtolower(array_pop(explode("\.", $userfile_name))); |
25 | d072e29c | Florent Chuffart | if (in_array($ext, array("php", "php5", "cgi"))) { |
26 | d072e29c | Florent Chuffart | if(file_exists($userfile)) { |
27 | d072e29c | Florent Chuffart | unlink($userfile); |
28 | d072e29c | Florent Chuffart | } |
29 | d072e29c | Florent Chuffart | exit("ERROR 1, your file CAN NOT have this extension.<br/><a href='".$_SERVER["HTTP_REFERER"]."'>Back</a>"); |
30 | d072e29c | Florent Chuffart | } |
31 | d072e29c | Florent Chuffart | if (!file_exists($current_entry_raw_dir)) { |
32 | d072e29c | Florent Chuffart | mkdir($current_entry_raw_dir); |
33 | d072e29c | Florent Chuffart | } |
34 | d072e29c | Florent Chuffart | $dest_filename = str_replace(" ","_",substr($userfile_name, 0, strlen($userfile_name))); |
35 | d072e29c | Florent Chuffart | $dest_filepath = $current_entry_raw_dir . $dest_filename; |
36 | d072e29c | Florent Chuffart | if (file_exists($dest_filepath)) { |
37 | d072e29c | Florent Chuffart | if (file_exists($userfile)) { |
38 | d072e29c | Florent Chuffart | unlink($userfile); |
39 | d072e29c | Florent Chuffart | } |
40 | d072e29c | Florent Chuffart | exit("ERROR 2, this filename is already used. <br/><a href='".$_SERVER["HTTP_REFERER"]."'>Back</a>"); |
41 | d072e29c | Florent Chuffart | } |
42 | d072e29c | Florent Chuffart | if (!copy($userfile, $dest_filepath)){ |
43 | d072e29c | Florent Chuffart | if (file_exists($userfile)) { |
44 | d072e29c | Florent Chuffart | unlink($userfile); |
45 | d072e29c | Florent Chuffart | } |
46 | d072e29c | Florent Chuffart | exit("ERROR 3, problem copying file. <br/><a href='".$_SERVER["HTTP_REFERER"]."'>Back</a>"); |
47 | d072e29c | Florent Chuffart | } |
48 | d072e29c | Florent Chuffart | if(file_exists($userfile)) { |
49 | d072e29c | Florent Chuffart | unlink($userfile); |
50 | d072e29c | Florent Chuffart | } |
51 | d072e29c | Florent Chuffart | } |
52 | d072e29c | Florent Chuffart | /*
|
53 | d072e29c | Florent Chuffart | * VIEW
|
54 | d072e29c | Florent Chuffart | */
|
55 | d072e29c | Florent Chuffart | $in_edit_mode = $_REQUEST["PME_sys_operation"] == "Change" || $_REQUEST["PME_sys_operation"] == "PME_op_Change"; |
56 | d072e29c | Florent Chuffart | |
57 | d072e29c | Florent Chuffart | if ($in_edit_mode) { |
58 | d072e29c | Florent Chuffart | $raw_dir_form = <<<EOD |
59 | 0ce29891 | Florent Chuffart | <div class="centered_form">
|
60 | 0ce29891 | Florent Chuffart | <i>Upload a file to the raw directory of this entry</i>
|
61 | 0ce29891 | Florent Chuffart | <br/>
|
62 | 0ce29891 | Florent Chuffart | <br/>
|
63 | 0ce29891 | Florent Chuffart | <form action='' method='post' enctype='multipart/form-data'>
|
64 | 0ce29891 | Florent Chuffart | <fieldset>
|
65 | 0ce29891 | Florent Chuffart | <legend>Upload Raw File</legend>
|
66 | 0ce29891 | Florent Chuffart | <input type='hidden' name='PME_sys_operation' value='PME_op_Change'/>
|
67 | 0ce29891 | Florent Chuffart | <input type='hidden' name='PME_sys_rec' value='$this->rec'/>
|
68 | 0ce29891 | Florent Chuffart | <input type='hidden' name='action' value='ADD_RAW_FILE'/>
|
69 | 0ce29891 | Florent Chuffart | <input name='userfile' type='file' size='10'/>
|
70 | 0ce29891 | Florent Chuffart | <input type='button' name='send' value='Upload' onclick='return this.form.submit();'/>
|
71 | 0ce29891 | Florent Chuffart | </fieldset>
|
72 | 0ce29891 | Florent Chuffart | </form>
|
73 | 0ce29891 | Florent Chuffart | </div>
|
74 | d072e29c | Florent Chuffart | EOD;
|
75 | d072e29c | Florent Chuffart | } |
76 | d072e29c | Florent Chuffart | |
77 | d072e29c | Florent Chuffart | if (file_exists($current_entry_raw_dir)) { |
78 | d072e29c | Florent Chuffart | $fp = fopen(LABSTOCK_SERVER . $current_entry_raw_dir, 'r', false); |
79 | d072e29c | Florent Chuffart | $raw_dir_content = preg_replace("/a href=\"/", "a href=\"" . LABSTOCK_SERVER . $current_entry_raw_dir, stream_get_contents($fp)); |
80 | d072e29c | Florent Chuffart | preg_match("'<table>(.*?)</table>'si", $raw_dir_content, $match); |
81 | d072e29c | Florent Chuffart | // print_r($match);
|
82 | d072e29c | Florent Chuffart | $raw_dir_frame = "<table>" . $match[1] . "</table>"; |
83 | d072e29c | Florent Chuffart | } |
84 | d072e29c | Florent Chuffart | } |
85 | d072e29c | Florent Chuffart | |
86 | 0ce29891 | Florent Chuffart | |
87 | 0ce29891 | Florent Chuffart | if ($raw_dir_form != "" | $raw_dir_frame != "") { |
88 | 0ce29891 | Florent Chuffart | $to_be_post_list_content .= <<<EOD |
89 | 0ce29891 | Florent Chuffart | <div class="sheet">
|
90 | 0ce29891 | Florent Chuffart | $raw_dir_form
|
91 | 0ce29891 | Florent Chuffart | $raw_dir_frame
|
92 | 0ce29891 | Florent Chuffart | </div>
|
93 | d072e29c | Florent Chuffart | EOD;
|
94 | 0ce29891 | Florent Chuffart | } |
95 | 0ce29891 | Florent Chuffart | |
96 | d072e29c | Florent Chuffart | ?> |