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