Statistiques
| Branche: | Révision :

root / src / raw_dir.MVC.php @ a9b72d88

Historique | Voir | Annoter | Télécharger (3,2 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 ($_FILES["userfile"]["error"]) {
11
  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
}
13

    
14

    
15
if ($current_object) {
16
  $current_class_raw_dir = "raw_dirs/$this->tb";
17
  $current_entry_raw_dir = "$current_class_raw_dir/$this->rec/";
18
  if ($_REQUEST["action"] == "ADD_RAW_FILE") {
19
    if (!file_exists($current_class_raw_dir)) {
20
      mkdir($current_class_raw_dir);
21
    }
22
    $userfile = $_FILES["userfile"]["tmp_name"];
23
    $userfile_name = $_FILES["userfile"]["name"];
24
    $ext = strtolower(array_pop(explode("\.", $userfile_name)));
25
    if (in_array($ext, array("php", "php5", "cgi"))) {
26
      if(file_exists($userfile)) {
27
        unlink($userfile);
28
      }
29
      exit("ERROR 1, your file CAN NOT have this extension.<br/><a href='".$_SERVER["HTTP_REFERER"]."'>Back</a>");
30
    }
31
    if (!file_exists($current_entry_raw_dir)) {
32
      mkdir($current_entry_raw_dir);
33
    }
34
    $dest_filename = str_replace(" ","_",substr($userfile_name, 0, strlen($userfile_name)));
35
    $dest_filepath = $current_entry_raw_dir . $dest_filename;
36
    if (file_exists($dest_filepath)) {
37
      if (file_exists($userfile)) {
38
        unlink($userfile);
39
      }
40
      exit("ERROR 2, this filename is already used. <br/><a href='".$_SERVER["HTTP_REFERER"]."'>Back</a>");
41
    }
42
    if (!copy($userfile, $dest_filepath)){
43
      if (file_exists($userfile)) {
44
        unlink($userfile);
45
      }
46
      exit("ERROR 3, problem copying file. <br/><a href='".$_SERVER["HTTP_REFERER"]."'>Back</a>");
47
    }
48
    if(file_exists($userfile)) {
49
      unlink($userfile);
50
    }
51
  }
52
  /*
53
  * VIEW
54
  */
55
  $in_edit_mode = $_REQUEST["PME_sys_operation"] == "Change" || $_REQUEST["PME_sys_operation"] == "PME_op_Change";
56

    
57
  if ($in_edit_mode) {  
58
    $raw_dir_form = <<<EOD
59
  <div class="centered_form">
60
    <i>Upload a file to the raw directory of this entry</i>
61
    <br/>
62
    <br/>
63
    <form action='' method='post' enctype='multipart/form-data'>
64
      <fieldset>
65
      <legend>Upload Raw File</legend>
66
        <input type='hidden' name='PME_sys_operation' value='PME_op_Change'/>
67
        <input type='hidden' name='PME_sys_rec' value='$this->rec'/>
68
        <input type='hidden' name='action' value='ADD_RAW_FILE'/>
69
        <input name='userfile' type='file' size='10'/>
70
        <input type='button' name='send' value='Upload' onclick='return this.form.submit();'/>
71
      </fieldset>
72
    </form>
73
  </div>
74
EOD;
75
  }
76

    
77
  if (file_exists($current_entry_raw_dir)) {
78
    $fp = fopen(LABSTOCK_SERVER . $current_entry_raw_dir, 'r', false);
79
    $raw_dir_content = preg_replace("/a href=\"/", "a href=\"" . LABSTOCK_SERVER . $current_entry_raw_dir, stream_get_contents($fp));
80
    preg_match("'<table>(.*?)</table>'si", $raw_dir_content, $match);
81
    // print_r($match);
82
    $raw_dir_frame = "<table>" . $match[1] . "</table>";
83
  }
84
}
85

    
86

    
87
if ($raw_dir_form != "" | $raw_dir_frame != "") {
88
  $to_be_post_list_content .= <<<EOD
89
    <div class="sheet">
90
    $raw_dir_form
91
    $raw_dir_frame
92
    </div>
93
EOD;
94
}
95

    
96
?>