Menu

[2eb2a2]: / docs_upload.php  Maximize  Restore  History

Download this file

91 lines (73 with data), 3.0 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
<?php session_start(); ?>
<html>
<head>
<title>deltasql - Adding Documents</title>
<link rel="stylesheet" type="text/css" href="deltasql.css">
<link rel="shortcut icon" href="pictures/favicon.ico" />
</head>
<body>
<?php
include("head.inc.php");
include("utils/utils.inc.php");
include("utils/constants.inc.php");
include("conf/config.inc.php");
$scriptid = $_POST['id'];
$version = $_POST['version'];
$hasdocs = $_POST['hasdocs'];
if ($scriptid=="") exit;
$uploadOk = 1;
$target_dir = getcwd() . "/upload/";
//echo $target_dir;
$my_filename=basename($_FILES["fileToUpload"]["name"]);
if ($my_filename=="") die("<font color='red'><b>No filename specified.</b></font>");
$my_filetype= pathinfo($my_filename,PATHINFO_EXTENSION);
$my_filesize=$_FILES["fileToUpload"]["size"];
if ($my_filesize > 10000000) {
$uploadOk = 0;
die("<font color='red'><b>Sorry, your file is too large (10MB).</b></font>");
}
// TODO: do other checks on the uploaded file, if necessary.
if ($uploadOk == 0) {
die("Sorry, your file was not uploaded.");
// if everything is ok, try to upload file
// redirect to hasdocs;
} else {
mysql_connect($dbserver, $username, $password);
@mysql_select_db($database) or die("Unable to select database");
// decide first if we need to rename the file because we already have it in the directory with the same name
$querycheck = "select count(*), max(id) from tbscriptdocument where name='$my_filename'";
$resultcheck = mysql_query($querycheck);
$count = mysql_result($resultcheck, 0, "count(*)");
$newid = mysql_result($resultcheck, 0, "max(id)");
if ($count>=1) {
// we choose another name with underscore script id
$path_parts = pathinfo($my_filename);
$newid = $newid + 1;
$my_filename = $path_parts['filename']."_$newid.".$path_parts['extension'];
$warning_already_uploaded=1;
}
else $warning_already_uploaded=0;
$target_file = $target_dir . $my_filename;
if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
echo "The file $my_filename has been uploaded.<br>";
} else {
die("<font color='red'><b>Sorry, there was an error uploading your file. Does the deltasql/upload subdirectory have correct rights for the Apache user?</b></font>");
}
$query="INSERT INTO tbscriptdocument (id, script_id, name, size, insert_dt) VALUES ('', $scriptid, '$my_filename', $my_filesize, NOW());";
mysql_query($query);
$query2="UPDATE tbscript set hasdocs=1 where id=$scriptid";
mysql_query($query2);
mysql_close();
if ($warning_already_uploaded==1) {
echo "<font color='red'><b>Warning, a file with the same name has already been uploaded. Therefore, the filename was changed to $my_filename.</b></font><br>";
echo "Click <a href='docs_manage.php?id=$scriptid&version=$version&hasdocs=1'>here</a> to go back to previous page...";
}
else
js_redirect("docs_manage.php?id=$scriptid&version=$version&hasdocs=1");
}
?>
<?php
include("bottom.inc.php");
?>
</body>
</html>
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.