PEAK XOOPS - XoopsMediaUploader in englishin japanese

XoopsMediaUploader

  • You cannot open a new topic into this forum
  • Guests cannot post into this forum
Previous post - Next post | Parent - Children.1 | Posted on 2005/8/14 6:10
FutureSpy  伍長 From: 世界のどっかで  Posts: 70
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
Votes:0 Average:0.00
Previous post - Next post | Parent - Children.1 | Posted on 2005/8/15 16:41
GIJOE  先任軍曹   Posts: 4110
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.

Votes:0 Average:0.00
Previous post - Next post | Parent - Children.1 | Posted on 2005/8/16 0:43
FutureSpy  伍長 From: 世界のどっかで  Posts: 70
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.jpg
1. 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.jpg
1. 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
Votes:8 Average:0.00

question Re: XoopsMediaUploader

msg# 1.1.1.1
Previous post - Next post | Parent - No child | Posted on 2005/8/24 6:56
GIJOE  先任軍曹   Posts: 4110
英語で説明するのは難しそうなので、日本語で書きます。

結論から言えば、そこまで判っているなら大丈夫、です。
最初のアップロードで、まずはDocumentRoot外のいずれかのフォルダにコピーします。$_FILES使えば良いでしょう。
この時点では、それだけでokです。

次の承認ステージでOKなら、そのフォルダから、/modules/mail/attachments
にコピーするのですが、その前段に、ファイルの拡張子チェックを入れれば良いでしょう。MIME-Typeチェックは本質的には何の意味もないので、何もしなくて良いですよ。

あとは、cronを回して、そのフォルダの古いファイルを消すだけです。

大事なのは、ファイルを一時的に保存するフォルダを、DocumentRoot外とすることです。そうしないと、アップロードした直後にアクセスされます。

一次保存先をDBとしても良いでしょうね。それなら、cronすら要りません。
Votes:15 Average:4.67

  Advanced search


Login
Username or e-mail:

Password:

Remember Me

Lost Password?

Register now!