Subversion Repositories computer_asset_manager_v1

Rev

Rev 59 | Rev 63 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 rodolico 1
<?php
54 rodolico 2
   include_once( '../../header.php' );
3
   include_once( './functions.php' );
4
 
5
   $result = '';
55 rodolico 6
   $debug = '';
59 rodolico 7
   if ( isset( $_REQUEST['uploadfile'] ) ) {
55 rodolico 8
      // clean up the input first
9
      $client_id = cleanInput( $_REQUEST['client_id'] );
10
      $site_id = cleanInput( $_REQUEST['site_id'] );
56 rodolico 11
      $device_id = cleanInput( $_REQUEST['device_id'] );
12
      $name = cleanInput( $_REQUEST['name'], $_FILES['fileToUpload']['name'] );
13
      $description = cleanInput( $_REQUEST['description'] );
55 rodolico 14
      $mime_type_id = $_REQUEST['mime_type'];
15
      // mime_type_id can be passed in, calculated from the 'type' of $_FILES, or looked up by extension
16
      if ( $mime_type_id == 0 ) { // we need to calculate the mime type (auto mode)
17
         // see if $_FILES has the info
18
         $mime_type_id = check_mime_type( $_FILES['fileToUpload']['type'] );
19
         if ( $mime_type_id === null ) { // no, so see if we can figure it out from the file name
20
            $mime_type_id = check_mime_type( pathinfo($_FILES['fileToUpload']['name'], PATHINFO_EXTENSION) );
21
         }
22
      }
23
      $debug = "client_id   =[$client_id]<br />
24
                site_id     =[$site_id]<br />
25
                device_id   =[$device_id]<br />
26
                name        =[$name]<br />
27
                mime_type_id=[$mime_type_id]<br />
28
                description =[$description]<br />";
29
      /*
30
       * this documentation will use the following example
31
       * A file, joe.csv, is uploaded and attached to the client
32
       * Walder IP Law. makeFileName discovers it to be file number
33
       * 123456 (based on an internal counter)
34
       * All comments below show what is returned
35
       */
54 rodolico 36
      $result = makeFileName( 
37
            $_FILES['fileToUpload']['name'], 
38
            $device_id, 
39
            $client_id, 
40
            $site_id 
41
            );
55 rodolico 42
      // at this point, we have 12/34/123456-c-Walder IP Law.csv
54 rodolico 43
      if ( $result['valid'] ) {
44
         $nameOnDisk = $result['filename'];
55 rodolico 45
         $saveTo = getAbsolutePath( $nameOnDisk );
46
         // $saveT now has document root, etc... prepended, so
59 rodolico 47
         // /var/www/computer_asset_management/modules/files/file_storage/12/34/123456-c-Walder IP Law.csv
55 rodolico 48
         if ( makePath( $saveTo ) ) {
49
            $result = "Path Made - $saveTo";
50
            if ( ( move_uploaded_file( $_FILES["fileToUpload"]["tmp_name"], $saveTo ) ) ) {
59 rodolico 51
               $result = addfile(
55 rodolico 52
                              $nameOnDisk,
53
                              $device_id, 
54
                              $client_id, 
55
                              $site_id,
56
                              isset( $_REQUEST['mime_type'] ) ? $_REQUEST['mime_type'] : $_FILES["fileToUpload"]['type'],
57
                              $name,
58
                              $description
59
                           );
59 rodolico 60
               $result = $result === null ? "Could not add file<br />$nameOnDisk<br />to database" : 'Success';
55 rodolico 61
            } else {
62
               $result = "Failed to upload to disk<br />$saveTo";
63
            } // if move_uploaded_file .. else
54 rodolico 64
         } else {
55 rodolico 65
            $result = "failed to make path<br />$saveTo";
54 rodolico 66
         }
67
      } else {
68
         $result = $result['message'];
69
      } // if nameOnDisk .. else
59 rodolico 70
   } // if isset uploadfile
1 rodolico 71
?>
72
<?xml version="1.0" encoding="utf-8"?>
73
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
74
<html xmlns="http://www.w3.org/1999/xhtml">
75
<head>
76
  <title>Daily Data - Computer Asset Management Program</title>
77
  <link rel="stylesheet" type="text/css" href="../../camp.css">
78
</head>
79
<body>
80
<?php include_once('../../menu.php'); ?>
81
<div id="content">
55 rodolico 82
   <?php 
83
      if ( isset( $result ) ) print "<h3>$result</h3>";
56 rodolico 84
      //if ( isset( $debug ) ) print "<h3>$debug</h3>";
55 rodolico 85
    ?>
59 rodolico 86
   <p>Choose only <b>one</b> of device, site or client to add the file to</p>
1 rodolico 87
  <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
88
    <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
89
    <table>
90
       <tr>
91
          <td>
92
             Attach To Device
93
          </td>
94
          <td>
54 rodolico 95
             <select name='device_id' >
1 rodolico 96
                <option value='0'>------------</option>
54 rodolico 97
                <?php print queryToSelect('select device_id, Device from view_current_client_systems order by Device' ); ?>
1 rodolico 98
             </select>
99
          </td>
100
       </tr>
101
       <tr>
102
          <td>
103
             Attach To Site
104
          </td>
105
          <td>
54 rodolico 106
             <select name='site_id' >
1 rodolico 107
                <option value='0'>------------</option>
54 rodolico 108
                <?php print queryToSelect('select site_id, name from view_current_client_site order by name' ); ?>
1 rodolico 109
             </select>
110
          </td>
111
       </tr>
112
       <tr>
113
          <td>
114
             Attach To Client
115
          </td>
116
          <td>
54 rodolico 117
             <select name='client_id' >
1 rodolico 118
                <option value='0'>------------</option>
54 rodolico 119
                <?php print queryToSelect('select client_id, name from view_current_client order by name' ); ?>
1 rodolico 120
             </select>
121
          </td>
122
       </tr>
123
       <tr>
124
          <td>
125
             Mime Type
126
          </td>
127
          <td>
55 rodolico 128
             <select name='mime_type_id' >
54 rodolico 129
                <option value='0'>Autodetect</option>
59 rodolico 130
                <?php print queryToSelect("select file_mime_type_id, concat( extension, ' (', mime_type, ')') from file_mime_type order by extension" ); ?>
1 rodolico 131
             </select>
132
          </td>
133
       </tr>
134
       <tr>
135
          <td>
59 rodolico 136
             file Name
1 rodolico 137
          </td>
138
          <td>
139
             <input type="text" name="name" size="30" maxlength="64" />
140
          </td>
141
       </tr>
142
       <tr>
55 rodolico 143
          <td valign='top'>
1 rodolico 144
             Description
145
          </td>
146
          <td>
55 rodolico 147
             <textarea name="description" cols='50' rows='5'></textarea>
1 rodolico 148
          </td>
149
       </tr>
150
       <tr>
151
          <td>
152
             Choose File
153
          </td>
154
          <td>
54 rodolico 155
             <input name="fileToUpload" type="file" />
1 rodolico 156
          </td>
157
       </tr>
158
       <tr>
159
          <td colspan='2' align="center">
59 rodolico 160
             <input type="submit" name="uploadfile" value="Upload" />
1 rodolico 161
          </td>
162
       </tr>
163
    </table>
164
  </form>
165
</div>
166
 
167
</body>
168
</html>
169