Hi, GIJOE.
It has nothing to do with your modules, so I don't know whether it's okay to ask it here or not, but anyways I'm already doing it... ^^'
I'm making a hack of contact module and I'm trying to add attached files feature.
The question is about XoopsMediaUploader class. I'd like to know if to use fetchMedia I have to also use upload. (I want it to check the file without storing it on cache)
My code is a little messy, but here's a piece of it:
if ($xoopsModuleConfig['mailform_attach'] == 1) {
$_POST['xoops_upload_file'][0] = $_SESSION['xoops_upload_file'][0];
include_once(XOOPS_ROOT_PATH."/modules/mail/class/uploader.php");
$uploader = new MailMediaUploader($xoopsModuleConfig['mailform_attachdir'], $xoopsModuleConfig['mailform_attachmime'],$xoopsModuleConfig['mailform_attachmaxsize']);
if($uploader->fetchMedia($_POST['xoops_upload_file'][0])){//if($uploader->fetchMedia($_POST['xoops_upload_file'][0]) && $uploader->upload()){
//unlink($uploader->getSavedDestination());
}else{
$errflg=true;
$errmsg = $uploader->getErrors();
//unlink($uploader->getSavedDestination());
}
//$_SESSION['filename'] = $_FILES['attach']['name'];
}
This code will show after the user submits the form and is directed to a confirmation screen.
I thought about using upload() and after that using unlink to delete it, but it's kind of inefective, since it'd have to upload it again in the next screen if the file is approved.
Any ideas?
Thanks in advance m(_ _)m
-Yuji
hi Yuji.
I'm sorry that I don't understand well what you want.
The best way is using graphics.
I understand like this:
-> display a form with upload (1)
<- upload by a user (2)
-> display confirmation (3)
<- push OK (4)
-> display success (5a)
----> send e-mail (5b)
If you want to implement, it is not a problem of XoopsMediaUploader.
You have to make a directory for temporary uploads out of DocumentRoot.
A temporary uploaded file made by system is deleted just after (3).
Thus, you can't use the file.
You'd better not to use XoopsMeidaUploader.
using $_FILES with PHP official manual is the best way I think.
GIJOE, thanks for your reply.
I'm not sure if you meant -that- by graphics, but let's try:
(1) Form
http://www.polarhome.com:793/~rakuen/screen1.jpg1. You fill in the form and select the file to upload, then it sends the form and upload the file to a temporary folder (in this case modules/mail/attachments).
====
(2) Confirmation Screen
http://www.polarhome.com:793/~rakuen/screen2.jpg1. The file is stored and checked by a copy of XoopsMediaUploder class (MailMediaUploader).
2. If the file is okay, it lets you send the e-mail. Otherwise, if it's a invalid file, it deletes using unlink() and not let you hit the Submit button.
3. When you hit the submit button, it sends the form plus the file (if any attachments) and deletes or not the file (defined by xoopsConfig) through unlink().
The problem lies here. Let's say someone fills in the form and upload a file. It sends the file and it's okay, ready to be sent. Then he gives up and close the browser window. The file will still be stored in the folder modules/mail/attachments. I could just get it to run a cronjob to clean the folder or get it to run everytime a form is sent, but I wanted to keep a copy of all attachments in the folder just like I keep a copy in the DB of every message sent.
So I wanted it to check the file first before storing it on the attachments folder. But when I use fetchMedia without upload() just like that:
if($uploader->fetchMedia($_POST['xoops_upload_file'][0])){
it's unable to check whether the extension/MIME type is allowed or the size is inside the limit.
The only thing I came up with was having it to upload to a temp folder. If the file is okay keep it there, otherwise delete it. Then, when the user hits the submit button, if the e-mail is sent successfully, move the file to another folder where the backup'ed attachments will be stored, and clear the temp folder (just to get rid off the files uploaded by someone but not sent successfully). Is there any better idea?
I'm sorry if it's not very clear again. If so, let me know and I'll try to draw a scheme of it.
I'll take a look at $_FILES later. ^^
Thanks again!
-Yuji