-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathupload_file.php
More file actions
executable file
·130 lines (116 loc) · 4.34 KB
/
Copy pathupload_file.php
File metadata and controls
executable file
·130 lines (116 loc) · 4.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
<?php
/* U P L O A D _ F I L E . P H P
* BRL-CAD
*
* Copyright (c) 1995-2013 United States Government as represented by
* the U.S. Army Research Laboratory.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
* version 2.1 as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this file; see the file named COPYING for more
* information.
*/
/** @file geometry_viewer/upload_file.php
*
*/
include 'accounts/auth.php';
include 'functions.php';
include 'config.php';
/**
* This variable hold 1, if upload completes, 2 if
* file already exists, otherwise 0.
*/
$uploadComplete = 0;
if ($_FILES["file"]["error"] > 0) {
echo "Error: " . $_FILES["file"]["error"] . "<br>";
$uploadComplete = 0;
} else if (file_exists("$uploadPath/" . $_FILES["file"]["name"])) {
$uploadComplete = 2;
} else {
move_uploaded_file($_FILES["file"]["tmp_name"],
"$uploadPath/" . $_FILES["file"]["name"]);
$uploadComplete = 1;
}
/**
* Holds the names of entities that to be displayed. variable is
* passed to WebGL through header.
*/
$redirectionData = NULL;
$objFileName = NULL;
/** Holds the name of uploaded database file. */
$dbFileName = $_FILES["file"]["name"];
/**
* Database file name is splited into its components, i.e. file
* name and extension and stored in array.
*/
$dbNameComponents = explode(".", $dbFileName);
/** Copy the name of file into variable. */
$dbFilePreffix = $dbNameComponents[0];
/**
* Command that lists the entities of a BRL-CAD database file is
* copied into a variable.
*/
$cmd = "$mgedPath -c $uploadPath/$dbFileName ls -a 2>&1";
/** Output of command is stored into variable as string. */
$out = shell_exec($cmd);
/**
* Split stirng and storing names of entities
* into array.
*/
$list = explode(" ", $out);
/** Count total number of entities. */
$totalEntities = count($list) - 2;
/** Number of entities to be displayed directly after upload. */
if ($totalEntities < 5) {
$n = $totalEntities;
} else {
$n = 5;
}
/**
* If file already exits, upload fails and models of entities
* of pre existing file are displayed.
*/
if ($uploadComplete == '2') {
for ($i = 0; $i < $n; $i++) {
if ($list[$i] == "_GLOBAL") {
$i = $i + 1;
$n = $n + 1;
/** This code has chances to be removed in future. */
$objFileName = $objPath.$dbFilePreffix."_".$list[$i].".obj";
$redirectionData = $redirectionData."|".$objFileName;
} else {
$objFileName = $objPath.$dbFilePreffix."_".$list[$i].".obj";
$redirectionData = $redirectionData."|".$objFileName;
}
}
header('Location: model_display.php?entitiesString='.urlencode($out).'&dbFileName='.urlencode($dbFileName));
} else if ($uploadComplete == '1') {
for ($i = 0; $i < $n; $i++) {
if ($list[$i] == "_GLOBAL") {
$i = $i + 1;
$n = $n + 1;
$objFileName = $objPath.$dbFilePreffix."_".$list[$i].".obj";
$redirectionData = $redirectionData."|".$objFileName;
} else {
$objFileName = $objPath.$dbFilePreffix."_".$list[$i].".obj";
$redirectionData = $redirectionData."|".$objFileName;
}
}
header('Location: model_display.php?entitiesString='.urlencode($out).'&dbFileName='.urlencode($dbFileName));
}
/*
* Local Variables:
* mode: PHP
* tab-width: 8
* End:
* ex: shiftwidth=4 tabstop=8
*/
?>