minor changes to prior commit
[openemr.git] / interface / patient_file / upload_dialog.php
blob360d72e97430095bf5d88fdbccf5f4e642f98b1f
1 <?php
2 /**
3 * This script upload image to file.
5 * Copyright (C) 2009-2010 Rod Roark <rod@sunsetsystems.com>
7 * LICENSE: This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://opensource.org/licenses/gpl-license.php>;.
18 * @package OpenEMR
19 * @author Rod Roark <rod@sunsetsystems.com>
20 * @author Roberto Vasquez <robertogagliotta@gmail.com>
21 * @link http://www.open-emr.org
24 require_once("../globals.php");
26 $patientid = $_REQUEST["patientid"];
27 $what = $_REQUEST["file"];
29 $patientdir = $GLOBALS['OE_SITE_DIR'] . "/documents/$patientid";
30 $imagedir = "$patientdir/demographics";
32 <html>
33 <head>
34 <title>Upload Image</title>
35 <script type="text/javascript" src="<?php echo $webroot ?>/interface/main/tabs/js/include_opener.js"></script>
36 <link rel="stylesheet" href="<?php echo xl($css_header, 'e');?>" type="text/css">
37 </head>
38 <body>
40 <?php
41 $errmsg = '';
43 if ($_POST["form_submit"] || $_POST["form_delete"]) {
44 if (!file_exists($patientdir)) {
45 mkdir($patientdir);
48 if (!file_exists($imagedir)) {
49 mkdir($imagedir);
52 check_file_dir_name($what);
53 $filename = "$imagedir/$what.jpg";
55 if ($_POST["form_delete"]) {
56 unlink($filename);
57 } else {
58 // Check if the upload worked.
60 if (! $errmsg) {
61 if (! is_uploaded_file($_FILES['userfile']['tmp_name'])) {
62 $errmsg = "Upload failed! Make sure the path/filename is valid " .
63 "and the file is less than 4,000,000 bytes.";
67 // Copy the image to its destination.
69 if (! $errmsg) {
70 /***************************************************************
71 $tmp = exec("/usr/bin/convert -resize 150x150 " .
72 ($_POST["form_normalize"] ? "-equalize " : "") .
73 $_FILES['userfile']['tmp_name'] .
74 " $filename 2>&1");
75 if ($tmp)
76 $errmsg = "This is not a valid image, or its format is unsupported.";
77 ***************************************************************/
79 if (!move_uploaded_file($_FILES['userfile']['tmp_name'], $filename)) {
80 $errmsg = "Internal error accessing uploaded file!";
85 // Write JavaScript for final disposition by the browser.
87 echo "<script LANGUAGE=\"JavaScript\">\n";
88 if ($errmsg) {
89 $errmsg = strtr($errmsg, "\r\n'", " ");
90 echo "window.alert('$errmsg')\n";
91 echo "window.history.back()\n";
92 } else {
93 echo "opener.location.reload()\n";
94 echo "dlgclose()\n";
97 echo "</script>\n</body>\n</html>\n";
99 exit;
103 <center>
105 <p><b>Upload Image File</b></p>
107 </center>
109 <form method="post" name="main" action="upload_dialog.php?patientid=<?php echo attr($patientid) ?>&file=<?php echo attr($what) ?>" enctype="multipart/form-data">
110 <input type="hidden" name="MAX_FILE_SIZE" value="4000000">
112 <center>
114 <!-- Table required so input field does not start on a new line -->
115 <table border="0">
116 <tr>
117 <td style="font-size:11pt">
118 Send this file:
119 </td>
120 <td>
121 <input type="file" name="userfile" />
122 </td>
123 </tr>
124 </table>
127 <input type="submit" name="form_submit" value="Upload" />
128 <input type="button" value="Cancel" onclick="dlgclose()" />
129 <input type="submit" name="form_delete" value="Delete" />
131 </center>
133 </form>
135 </body>
136 </html>