-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathupload_ajax.php
More file actions
89 lines (86 loc) · 3.47 KB
/
upload_ajax.php
File metadata and controls
89 lines (86 loc) · 3.47 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
<?php
session_start() ;
$db_host = 'localhost' ;
$db_database = 'pd course' ;
$db_username = 'root' ;
$connection = mysql_connect($db_host, $db_username, 'pdogsserver');
if (!$connection)
die ("connection failed".mysql_error()) ;
mysql_query("SET NAMES 'utf8'");
$selection = mysql_select_db($db_database) ;
if (!$selection)
die ("selection failed".mysql_error()) ;
$acc = mysql_real_escape_string($_SESSION['account']);
$problem_dir = '.\\student\\'.$acc.'\\'.$_POST['hwID'];
$upfile = $problem_dir.'\\'.$acc.'-'.$_POST['hwID'].'.cpp';
$pdffile = $problem_dir.'\\'.$acc.'-'.$_POST['hwID'].'.pdf';
if (!isset($_SESSION['account'])){
header ("Location:index.php") ;
} else {
?>
<form method="POST" action="result.php" id="fileUploadForm" enctype="multipart/form-data">
<div class="hero-unit upload_section">
<p class="hw-id"> 作業序號放這裡 </p> <?php
if ($_POST['hwID'][0] == 'P'){
$query = "SELECT submit_code, submit_pdf FROM pd_hw WHERE p_id = '".$_POST['hwID']."'";
} else if ($_POST['hwID'][0] == 'L'){
$query = "SELECT submit_code, submit_pdf FROM lab_hw WHERE lab_id = '".$_POST['hwID']."'";
} else if ($_POST['hwID'][0] == 'E'){
$query = "SELECT submit_code, submit_pdf FROM exam WHERE exam_id = '".$_POST['hwID']."'";
}
$submit = mysql_query($query);
$fetch_submit = mysql_fetch_row($submit);
if ($fetch_submit[0] == true){ //需要上傳cpp檔 ?>
<p class="hw"> File format: .c or .cpp </p>
<p class="hw"> File size: max 3MBs</p>
<div class="fileupload fileupload-new" data-provides="fileupload"> <?php
if (file_exists($upfile)){ ?>
<div>
<a href="download_file.php? num= <?php echo $_POST['hwID'];?>&type=cpp" target="_blank">Submitted cpp file</a><br>
</div> <?php
} ?>
<div class="input-append">
<div class="uneditable-input span3">
<i class="icon-file fileupload-exists"></i>
<span class="fileupload-preview"></span>
</div>
<span class="btn btn-file">
<span class="fileupload-new">Select file</span>
<span class="fileupload-exists">Change File</span>
<input type="file" class="upload" name="upload"/>
</span>
<a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>
<a class="btn fileupload-exists upload-button" >Upload</a>
</div>
</div> <?php
}
if ($fetch_submit[1] == true){ //需要上傳pdf檔?>
<p class="hw"> File format: .pdf </p>
<p class="hw"> File size: max 3MBs</p>
<div class="fileupload fileupload-new" data-provides="fileupload"> <?php
if (file_exists($pdffile)){ ?>
<div>
<a href="download_file.php?num=<?php echo $_POST['hwID'];?>&type=pdf" target="_blank">Submitted pdf file</a>
</div> <?php
} ?>
<div class="input-append">
<div class="uneditable-input span3">
<i class="icon-file fileupload-exists"></i>
<span class="fileupload-preview"></span>
</div>
<span class="btn btn-file">
<span class="fileupload-new">Select file</span>
<span class="fileupload-exists">Change File</span>
<input type="file" class="pdfupload" name="pdfupload"/>
</span>
<a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>
<a class="btn fileupload-exists upload-button" >Upload</a>
</div>
</div> <?php
} ?>
</div>
</form>
<script src="js/upload.js"></script>
<?php
}
?>