]> Softwares of Agnibho - simpleipd.git/blob - www/attachments.php
show reference range
[simpleipd.git] / www / attachments.php
1 <?php
2 require(dirname(__DIR__)."/require.php");
3 $error="<p>";
4 $imgs="<div class='card mb-3 w-100'><div class='card-body'><div class='row'>";
5 $pdfs="<div class='card mb-3'><div class='card-body'>";
6 if(!empty($_GET["pid"])){
7 $pid=$_GET["pid"];
8 if(!empty($_FILES)){
9 if(in_array($_FILES["upload"]["type"], ["image/jpeg", "image/jpg", "image/png", "image/gif", "application/pdf"])){
10 if(!empty($_GET["name"])){
11 $name=$_GET["name"]."-";
12 }
13 else{
14 $name="";
15 }
16 $fname=str_replace("/", "", $pid)."-".$name.time()."-".rand(1000,9999).".".pathinfo($_FILES["upload"]["name"], PATHINFO_EXTENSION);
17 move_uploaded_file($_FILES["upload"]["tmp_name"], "data/attachments/".$fname);
18 if(!empty($_GET["req"])){
19 $db->omitRequisition($_GET["req"]);
20 }
21 }
22 else{
23 $error=$error."Only jpg, png, gif, pdf files are supported.";
24 }
25 }
26
27 foreach(glob("data/attachments/".str_replace("/", "", $pid)."-*") as $attach){
28 if(pathinfo($attach, PATHINFO_EXTENSION)=="pdf"){
29 $pdfs=$pdfs."<a href='".$attach."'>".pathinfo($attach, PATHINFO_BASENAME)."</a>";
30 }
31 else{
32 preg_match("/-([0-9]+)-/", pathinfo($attach, PATHINFO_FILENAME), $orig);
33 $imgs=$imgs."<div class='col-md-6'><figure><a href='".$attach."'><img class='w-100' src='".$attach."'></a><figcaption>Uploaded on: ".date("M d, Y h:i a", $orig[1])."</figcaption></figure></div>";
34 }
35 }
36 }
37 $imgs=$imgs."</div></div></div>";
38 $pdfs=$pdfs."</div></div>";
39 $error=$error."</p>";
40 ?>
41 <!DOCTYPE html>
42 <html>
43 <head>
44 <?php include(CONFIG_LIB."head.php");?>
45 <title>Attachments</title>
46 </head>
47 <body>
48 <div class="container">
49 <?php include(CONFIG_LIB."top.php");?>
50 <?php echo getInfo($pid);?>
51 <form class="mt-3 mb-3" method="post" enctype="multipart/form-data" <?php echo checkAccess("attachments", "form");?>>
52 <label for="upload">Select file to upload. JPG, PNG, GIF and PDF files are supported. Size limit: <span id="size-limit"><?php echo str_replace("M", "MB", ini_get("upload_max_filesize"));?></span><span id="upload-error"></span></label>
53 <input type="file" name="upload" id="upload" class="form-control">
54 <input type="submit" value="Upload" class="mt-2 btn btn-primary">
55 </form>
56 <div id="attachments">
57 <?php echo $pdfs;?>
58 <div class="row">
59 <?php echo $imgs;?>
60 </div>
61 </div>
62 <?php echo $error;?>
63 </div>
64 <?php include(CONFIG_LIB."foot.php");?>
65 </body>
66 </html>