public function upload($resize = NULL) { $cr = ERROR_OK; $model = NULL; // cleanup old upload temporary files $this->load->helper('slicer'); Slicer_cleanUploadFolder($this->config->item('temp')); if (FALSE !== $this->input->get('noresize')) { $resize = 'noresize'; } if ($_SERVER['REQUEST_METHOD'] == 'POST') { $array_model = array(); $upload_config = array('upload_path' => $this->config->item('temp'), 'allowed_types' => '*', 'overwrite' => TRUE, 'remove_spaces' => TRUE, 'encrypt_name' => TRUE); $this->load->library('upload', $upload_config); if ($this->upload->do_upload('f')) { $model = $this->upload->data(); $model_path = $model['full_path']; $array_model[] = $model_path; } else { if ($this->upload->do_upload('s1')) { $first_combine = TRUE; $model = $this->upload->data(); $array_model[] = $model['full_path']; foreach (array('s2') as $file_key) { if ($this->upload->do_upload($file_key)) { $first_combine = FALSE; $model = $this->upload->data(); $array_model[] = $model['full_path']; } else { if ($first_combine == TRUE) { $cr = ERROR_MISS_PRM; break; } } } } else { // treat error - missing gcode file $cr = ERROR_MISS_PRM; } } if ($cr == ERROR_OK) { if ($resize != 'noresize') { $cr = Slicer_addModel($array_model); } else { $array_return = array(); $cr = Slicer_addModel($array_model, TRUE, FALSE, $array_return); if ($cr == ERROR_OK) { $display = json_encode($array_return); $this->output->set_content_type(RETURN_CONTENT_TYPE_JSON); $this->load->library('parser'); $this->parser->parse('plaintxt', array('display' => $display)); return; } } } $this->_return_cr($cr); } else { //TODO change load view into parser? $this->load->view('template/rest/model_form'); } return; }
public function upload() { $template_data = array(); $error = NULL; $response = 0; $button_goto_slice = NULL; $bicolor = $this->config->item('nb_extruder') >= 2; $this->load->library('parser'); $this->load->helper('slicer'); $this->lang->load('sliceupload/upload', $this->config->item('language')); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $array_model = array(); $upload_config = array('upload_path' => $this->config->item('temp'), 'allowed_types' => '*', 'overwrite' => FALSE, 'remove_spaces' => TRUE); $this->load->library('upload', $upload_config); if ($this->upload->do_upload('file')) { $model = $this->upload->data(); $model_ext = strtolower($model['file_ext']); // we just let xml pass to check amf.xml by slicer itself $array_check = $bicolor ? array('.stl', '.amf', '.obj', '.xml') : array('.stl'); if (!is_null($model_ext) && !in_array($model_ext, $array_check)) { // we can treat extension error differently $error = t('fail_message_ext'); } else { $array_model[] = $model['file_name']; } } else { if ($this->upload->do_upload('file_c1')) { $first_combine = TRUE; $model = $this->upload->data(); $model_ext = strtolower($model['file_ext']); if (!is_null($model_ext) && $model_ext != '.stl') { // we can treat extension error differently $error = t('fail_message_ext'); } else { $array_model[] = $model['file_name']; foreach (array('file_c2') as $file_key) { if ($this->upload->do_upload($file_key)) { $first_combine = FALSE; $model = $this->upload->data(); $model_ext = strtolower($model['file_ext']); if (!is_null($model_ext) && $model_ext != '.stl') { // we can treat extension error differently $error = t('fail_message_ext'); } else { $array_model[] = $model['file_name']; } } else { if ($first_combine == TRUE) { $error = t('fail_message'); break; } } } } } else { // treat error - missing gcode file $error = t('fail_message'); } } if (is_null($error) && count($array_model)) { // load a wait page for adding model into slicer $template_data = array('wait_message' => t('wait_message'), 'return_button' => t('return_button'), 'model_name' => json_encode($array_model), 'fail_message' => t('fail_message'), 'fin_message' => t('fin_message'), 'key_smax' => SLICER_TITLE_MAXSCALE); $this->_parseBaseTemplate(t('sliceupload_upload_pagetitle'), $this->parser->parse('sliceupload/upload_wait', $template_data, TRUE)); return; } } if (0 == strlen(@file_get_contents($this->config->item('temp') . SLICER_FILE_HTTP_PORT)) && FALSE == $this->config->item('simulator')) { $this->output->set_header('Location: /sliceupload/restart?inboot=1'); return; } else { if (!Slicer_checkOnline(FALSE)) { $this->output->set_header('Location: /sliceupload/restart'); return; } } // cleanup old upload temporary files Slicer_cleanUploadFolder($this->config->item('temp')); if (ERROR_OK == Slicer_listModel($response) && $response != "[]" && ERROR_OK == Slicer_checkPlatformModel()) { $template_data = array('text' => t('button_goto_slice'), 'link' => '/sliceupload/slice', 'id' => 'goto_slice_button'); $button_goto_slice = $this->parser->parse('sliceupload/a_button', $template_data, TRUE); if (Slicer_checkSlicedModel()) { $template_data = array('text' => t('button_goto_result'), 'link' => '/sliceupload/slice?callback', 'id' => 'goto_result_button'); $button_goto_slice .= $this->parser->parse('sliceupload/a_button', $template_data, TRUE); } } // parse the main body $template_data = array('back' => t('back'), 'select_hint' => t('select_hint'), 'select_hint_multi' => t('select_hint_multi'), 'header_single' => t('header_single'), 'header_multi' => t('header_multi'), 'upload_button' => t('upload_button'), 'goto_slice' => $button_goto_slice, 'error' => $error, 'bicolor' => $bicolor ? 'true' : 'false'); $this->_parseBaseTemplate(t('sliceupload_upload_pagetitle'), $this->parser->parse('sliceupload/upload', $template_data, TRUE)); return; }