|
From: Benjamin C. <bc...@us...> - 2001-08-10 23:21:17
|
Update of /cvsroot/phpbt/phpbt
In directory usw-pr-cvs1:/tmp/cvs-serv6954
Modified Files:
attachment.php strings-en.php
Log Message:
Getting the attachments a little closer to working
Index: attachment.php
===================================================================
RCS file: /cvsroot/phpbt/phpbt/attachment.php,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- attachment.php 2001/08/10 13:51:48 1.1
+++ attachment.php 2001/08/10 23:21:13 1.2
@@ -23,33 +23,65 @@
include 'include.php';
+function show_attachment($attachid) {
+ global $q;
+
+ if (!is_numeric($attachid)) {
+ show_text($STRING['bad_attachment'], true);
+ return;
+ }
+ $ainfo = $q->grab("select a.BugID, FileName, MimeType, Project from Attachment a, Bug b where AttachmentID = $attachid and a.BugID = b.BugID");
+ if ($q->num_rows() != 1) {
+ show_text($STRING['bad_attachment'], true);
+ return;
+ }
+ $filename = join('/',array(INSTALLPATH, ATTACHMENT_PATH,
+ $ainfo['Project'], "{$ainfo['BugID']}-{$ainfo['FileName']}"));
+ if (!is_readable($filename)) {
+ show_text($STRING['bad_attachment'], true);
+ return;
+ }
+ header("Content-type: {$ainfo['MimeType']}");
+ @readfile($filename);
+}
+
function add_attachment($projectid, $bugid, $description) {
global $q, $HTTP_POST_FILES, $now, $u, $STRING;
if (!isset($HTTP_POST_FILES['attachment']) ||
$HTTP_POST_FILES['attachment']['tmp_name'] == 'none') {
- return false;
+ show_attachment_form($bugid, $STRING['give_attachment']);
+ return;
}
+
$filepath = INSTALLPATH.'/'.ATTACHMENT_PATH;
$tmpfilename = $HTTP_POST_FILES['attachment']['tmp_name'];
$filename = "$bugid-{$HTTP_POST_FILES['attachment']['name']}";
+
if (!is_dir($filepath)) {
show_attachment_form($bugid, $STRING['no_attachment_save_path']);
+ return;
}
+
if (!is_writeable($filepath)) {
show_attachment_form($bugid, $STRING['attachment_path_not_writeable']);
+ return;
}
+
if (!is_dir("$filepath/$projectid")) {
- #umask(011);
@mkdir("$filepath/$projectid", 0775);
}
+
if (!@move_uploaded_file($HTTP_POST_FILES['attachment']['tmp_name'],
"$filepath/$projectid/$filename")) {
show_attachment_form($bugid, $STRING['attachment_move_error']);
+ return;
}
- chmod("$filepath/$projectid/$filename", 0766);
+
+ @chmod("$filepath/$projectid/$filename", 0766);
$q->query("insert into Attachment (AttachmentID, BugID, FileName, Description, FileSize, MimeType, CreatedBy, CreatedDate) values (".$q->nextid('Attachment').", $bugid, '{$HTTP_POST_FILES['attachment']['name']}', '$description', {$HTTP_POST_FILES['attachment']['size']}, '{$HTTP_POST_FILES['attachment']['type']}', $u, $now)");
- return true;
+ $t->set_file('content', 'bugattachmentsuccess.html');
+ $t->set_var('bugid', $bugid);
}
function show_attachment_form($bugid, $error = '') {
Index: strings-en.php
===================================================================
RCS file: /cvsroot/phpbt/phpbt/strings-en.php,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- strings-en.php 2001/08/10 13:51:17 1.13
+++ strings-en.php 2001/08/10 23:21:13 1.14
@@ -51,9 +51,11 @@
'passwordmatch' => 'Those passwords don\'t match -- please try again',
'nobughistory' => 'There is no history for that bug',
'logintomodify' => 'You must be logged in to modify this bug',
+ 'give_attachment' => 'Please specify a file to upload',
'no_attachment_save_path' => 'Couldn\'t find where to save the file!',
'attachment_path_not_writeable' => 'Couldn\'t create a file in the save path',
- 'attachment_move_error' => 'There was an error moving the uploaded file'
+ 'attachment_move_error' => 'There was an error moving the uploaded file',
+ 'bad_attachment' => 'That attachment does not exist'
);
// Page titles
|