ถ้า Submit Post Action ไปไฟล์อื่น ต้องใส่ enctype="multipart/form-data" ด้วย
แต่กรณีนี้จะส่งผ่าน Java ไม่ต้อง Reload หน้า Web Code ดังนี้
HTML
- <div id="dialog-edit-upload" title="Upload รายงานความคืบหน้า Project หรือ PMC" style="display:none;">
- <form method="POST" enctype="multipart/form-data" id="myform">
- <div>Upload pdf ไฟล์ เพื่อแนบรายงานความคืบหน้าแต่ละเดือน</div>
- <table width='100%' border='0'>
- <tr>
- <td nowrap>ประจำเดือน : </td>
- <td><input name='P_Month' id='P_Month_field' size='3' readonly="readonly"><input type="hidden" name='PHPBBID' id='PHPBBID_field'></td>
- </tr>
- <tr>
- <td nowrap>Upload PDF ไฟล์ : </td>
- <td align='left' class='default'><input type="file" name="P_FILE_MONTH" id="P_FILE_MONTH_ID"></td>
- </tr>
- </table>
- </form>
- </div>
Java
- function editUpload(ACTION){
- var str = ACTION;
- var ActionArray = str.split(',');
- $('#P_Month_field').val('');
- $('#P_FILE_MONTH_ID').val('');
- $('#PHPBBID_field').val('');
- $('#PHPBBID_field').val(ActionArray[0]);
- $('#P_Month_field').val(ActionArray[1]);
- //var target = "project_upload.php?ACTION=" + ActionArray[0] + ',' + ActionArray[1];
- var target = "project_upload.php";
- $( "#dialog-edit-upload" ).dialog({
- resizable: false,
- width:420,
- height:250,
- modal: true,
- buttons: {
- "Yes": function() {
- //$('#PHPBBID_field').val() ;
- // Get form
- var form = $('#myform')[0];
- // Create an FormData object
- var data = new FormData(form);
- // If you want to add an extra field for the FormData
- //data.append("CustomField", "This is some extra data, testing");
- // disabled the submit button
- //$("#btnSubmit").prop("disabled", true);
- $.ajax({
- type: "POST",
- enctype: 'multipart/form-data',
- url: target,
- data: data,
- processData: false,
- contentType: false,
- cache: false,
- timeout: 800000,
- success: function(ret) {
- //alert("บันทึกข้อมูลสำเร็จ !");
- if(ret == 'OK'){
- alert("บันทึกข้อมูลสำเร็จ ");
- } else {
- alert("บันทึกข้อมูลไม่สำเร็จ กรุณาตรวจสอบ ! ");
- }
- $('#P_Month_field').val('');
- $('#P_FILE_MONTH_ID').val('');
- $('#PHPBBID_field').val('');
- },
- });
- $( this ).dialog( "close" );
- },
- Cancel: function() {
- $( this ).dialog( "close" );
- }
- }
- });
- }
PHP
- if(!empty($PHPBBID)){
- include($phpbb_root_path . 'includes/functions_posting.' . $phpEx);
- include($phpbb_root_path . 'includes/message_parser.' . $phpEx);
- $message_parser = new parse_message();
- $message_parser->parse_attachments('P_FILE_MONTH', 'post', 139, true, false, false);
- //$message_parser->parse_attachments('P_FILE_MONTH', 'post', $NumberForum, true, false, false);
- //function upload_attachment($form_name, $forum_id, $local = false, $local_storage = '', $is_message = false, $local_filedata = false);
- //$upload_parser = new parse_upload();
- //$upload_parser -> upload_attachment('P_FILE_MONTH', 18429, $local = false, $local_storage = '', $is_message = false, $local_filedata = false);
- $my_subject = "รายงานความคืบหน้าเดือน $P_Month";
- $my_text = "รายงานความคืบหน้าเดือน $P_Month";
- $poll = $uid = $bitfield = $options = '';
- generate_text_for_storage($my_subject, $uid, $bitfield, $options, false, false, false);
- generate_text_for_storage($my_text, $uid, $bitfield, $options, true, true, true);
- $data = array(
- 'forum_id' => 139,
- 'topic_id' => $PHPBBID,
- //'topic_id' => 18429,
- 'icon_id' => false,
- 'enable_bbcode' => true,
- 'enable_smilies' => true,
- 'enable_urls' => true,
- 'enable_sig' => true,
- 'message' => $my_text,
- 'message_md5' => md5($my_text),
- 'bbcode_bitfield' => $bitfield,
- 'bbcode_uid' => $uid,
- 'post_edit_locked' => 0,
- 'topic_title' => $my_subject,
- 'notify_set' => false,
- 'notify' => false,
- 'post_time' => 0,
- 'forum_name' => '',
- 'enable_indexing' => true,
- 'attachment_data' => $message_parser->attachment_data,
- 'filename_data' => $message_parser->filename_data
- );
- submit_post('reply', $my_subject, '', POST_NORMAL, $poll, $data);
- echo "OK";
- } else {
- echo "ERROR";
- }
ไม่มีความคิดเห็น:
แสดงความคิดเห็น