Implementing a "simple" multifile uploading solution
Hi guys,
I've been dealing with this issue also, as a client wanted to use their "proprietary" swf uploader.
This modification requires some PHP / JavaScript coding knowledge, but is in fact, pretty easy to implement once you've got it :)
I'll explain my method in a few simple steps, which work here, and should work in your installation if everything is done right.
Step 1.
Extract the "multiple.zip" attachment file in your osticket "include" dir which should result in: (/osticket)/upload/include/multiple/
In this directory you should have the following:
/files
/scripts
index.php
upload.php
upload.swf
viewticket.inc.php
Step 2.
Create a tmp directory under your osTicket installation and CHMOD o+w (give write rights).
For ex. /osticket/upload/tmp
This directory will be used to temporarily store the uploaded files on the server.
Step 3.
In this example I will include my version of the file /osticket/upload/include/client/viewticket.inc.php for reference.
I have modified it to be able to upload multiple attachments when posting a new message. (this is also the most simple example I could think of :) )
In fact, you should puzzle the documented content of the /multiple/index.php file, into your HTML from the original osTicket form. (not for noobies )
See the viewticket.inc.php file for reference on how to do this!
Step 4.
Edit the osTicket attachment processing code in /osticket/upload/tickets.php as follows, to process our temporarily stored files into real attachments
Search for the following piece of code (it's around line #49):
if(!$_POST)
$errors='Message required';
//check attachment..if any is set
if($_FILES) {
if(!$cfg->allowOnlineAttachments()) //Something wrong with the form...user shouldn't have an option to attach
$errors='File [ '.$_FILES rejected';
elseif(!$cfg->canUploadFileType($_FILES))
$errors='Invalid file type [ '.$_FILES';
elseif($_FILES>$cfg->getMaxFileSize())
$errors='File is too big. Max '.$cfg->getMaxFileSize().' bytes allowed';
}
if(!$errors){
//Everything checked out...do the magic.
if(($msgid=$ticket->postMessage($_POST,'Web'))) {
if($_FILES && $cfg->canUploadFiles() && $cfg->allowOnlineAttachments())
$ticket->uploadAttachment($_FILES,$msgid,'M');
$msg='Message Posted Successfully';
}else{
$errors='Unable to post the message. Try again';
}
}else{
$errors=$errors?$errors:'Error(s) occured. Please try again';
}
and modify it to the following:
if(!$_POST)
$errors='Message required';
//check attachment..if any is set
/*if($_FILES) {
if(!$cfg->allowOnlineAttachments()) //Something wrong with the form...user shouldn't have an option to attach
$errors='File [ '.$_FILES rejected';
elseif(!$cfg->canUploadFileType($_FILES))
$errors='Invalid file type [ '.$_FILES';
elseif($_FILES>$cfg->getMaxFileSize())
$errors='File is too big. Max '.$cfg->getMaxFileSize().' bytes allowed';
}*/
if(!$errors){
//Everything checked out...do the magic.
if(($msgid=$ticket->postMessage($_POST,'Web'))) {
if( isset($_SESSION) && is_array($_SESSION) && $cfg->canUploadFiles() && $cfg->allowOnlineAttachments()) {
$attachments = $_SESSION;
foreach ( (array)$attachments as $attachment ) {
$filename = $attachment;
// set tmp path
$tmp_attachment_dir = ROOT_DIR . 'tmp';
// open tmp files
$fp = fopen($tmp_attachment_dir.'/'.$filename, 'r');
$filedata = fread($fp, filesize($tmp_attachment_dir.'/'.$filename));
fclose($fp);
$ticket->saveAttachment($filename, $filedata, $msgid, 'M');
}
}
$msg='Message Posted Successfully';
}else{
$errors='Unable to post the message. Try again';
}
}else{
$errors=$errors?$errors:'Error(s) occured. Please try again';
}
Instead of using the normal "$ticket->uploadAttachment()" function to store our attachment file, I modified it to use the function for email fetching.
The function "$ticket->saveAttachment" does quite the same, except that you have to pass in the raw file data and a filename to store the file and attach it.
Now, that's all.
You are free to implement the technique further into osTicket forms. (for ex. the ticket creation form)
Or poke me on my forum message box or something.
Greets, and hoping to be of assistance,
Kimbo
[multiple.zip](https://forum.osticket.com/assets/files/migrated/e/765921969ccbf3c8cd6a7b35963e83d.zip)