protected function zip_upload($fobject, $name, $data, $action, $item) { $res = array(); $mtype = MIME::type_for_file($fobject->original_name); if ($mtype->type == 'application/zip;zip') { $zip = new ZipArchive(); $ro = $zip->open($fobject->path); if ($ro === true) { $dir = CMS::temp_dir() . '/' . $fobject->name; $dir_object = IO_FS::mkdir($dir, null, true); if ($dir_object) { $zip->extractTo($dir); $objects = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS)); foreach ($objects as $k => $object) { $base = trim($object->getBasename($object->getExtension()), '. '); if ('' !== $base) { $upload = Net_HTTP::Upload($object->getPathname(), $object->getFilename(), array('name' => $object->getFilename(), 'type' => MIME::type_for_file($object->getPathname())->type, 'tmp_name' => $object->getPathname(), 'error' => 0, 'size' => $object->getSize())); $res[] = $this->upload_file($upload, $name, $data, $action, $item); } } $dir_object->rm(); } $zip->close(); } } return $res; }
protected function process_uploads($item) { $id = $this->item_id($item); $uploaded = array(); $ruploaded = array(); $udirs = array(); $tmpdir = CMS::temp_dir(); foreach ($this->upload_fields as $field => $dir) { if (is_string($dir)) { $dir = rtrim($dir, '/'); if ($this->uploads_multi_dir) { $did = floor($id / 100) * 100; $dir .= "/{$did}"; } if (!IO_FS::exists($dir)) { $this->mkdirs($dir); } $udirs[$field] = $dir; } if (is_object($this->form[$field])) { $path = $this->form[$field]->path; $original_name = $this->form[$field]->original_name; $ext = ''; if ($m = Core_Regexps::match_with_results('{(\\.[a-z0-9_]+)$}i', $original_name)) { $ext = strtolower($m[1]); } $name = $this->upload_destination($id, $field, $ext, $original_name); if (is_string($dir) && $dir != '') { $name = "{$dir}/{$name}"; } $name = trim($name); move_uploaded_file($path, $name); $ncname = $tmpdir . '/upl-' . md5($name) . $ext; $ncres = @copy($name, $ncname); $type = self::$field_types[$this->form_fields[$field]['type']]; if ($type) { $r = $type->after_upload($name, $this->form_fields[$field]); if ($r) { $name = $r; } } $this->chmod_file($name); $old = trim($this->item_before_assign->{$field}); if ($old != '' && $name != $old && IO_FS::exists($old)) { IO_FS::rm($old); } $item->{$field} = $name; $uploaded[$field] = $ncres ? $ncname : $name; $ruploaded[$field] = $name; } } foreach ($udirs as $field => $dir) { $type = self::$field_types[$this->form_fields[$field]['type']]; if ($type) { $old = trim($this->item_before_assign->{$field}); $name = rtrim($udirs[$field], '/ ') . '/' . $this->upload_destination($id, $field, '.$$$', 'null.$$$'); $name = $type->after_all_uploads($field, $this->form_fields[$field], $name, $uploaded, $old); if ($name) { $this->chmod_file($name); if ($old != '' && $name != $old && IO_FS::exists($old)) { IO_FS::rm($old); } $item->{$field} = $name; } } } foreach ($uploaded as $field => $file) { if ($file != $ruploaded[$field]) { @unlink($file); } } }
public function dir_path($item, $code, $name, $data) { $item_id = $item ? $item->id() : 0; $key = "{$name}-{$item_id}-{$code}-{$data['private']}"; if ($item->mapper) { $key .= '-' . reset($item->mapper->options['table']); } if (isset($this->dir_paths[$key])) { return $this->dir_paths[$key]; } $dir = false; if (empty($item_id)) { $dir = CMS::temp_dir() . "/dir-{$code}"; } else { $dir = $item->homedir(isset($data['private']) && $data['private']); if ($dir == '') { die; } if ($dir[0] != '.' && $dir[0] != '/') { $dir = "./{$dir}"; } } $dir .= "/{$name}"; return $this->dir_paths[$key] = $dir; }
public function install_temp_dir() { return CMS::temp_dir() . '/stockroom/' . $this->code(); }
protected function process_uploads($item) { if (!isset($_FILES[$this->form->name])) { return; } $dir = CMS::temp_dir(); $files = $_FILES[$this->form->name]; foreach ($files['tmp_name'] as $field => $path) { $t = time(); $path = trim($path); if ($path == '') { continue; } $original_name = $files['name'][$field]; $original_name_we = $original_name; $ext = ''; $dotext = ''; if ($m = Core_Regexps::match_with_results('{^(.*)\\.([a-z0-9_]+)$}i', $original_name)) { $original_name_we = strtolower($m[1]); $ext = $m[2]; $dotext = ".{$ext}"; } $uplname = "uploaded-{$field}-{$t}{$dotext}"; $uplpath = "{$dir}/{$uplname}"; move_uploaded_file($path, $uplpath); CMS::chmod_file($uplpath); $this->uploaded_files[$field] = array('original_name' => $original_name, 'original_name_we' => $original_name_we, 'ext' => $ext, 'dotext' => $dotext, 'uplname' => $uplname, 'uplpath' => $uplpath, 'size' => $files['size'][$field], 'type' => $files['type'][$field]); } $uploads_extra = array('old_item' => $this->item_before_assign, 'id' => $this->item_id($item), 'homedir' => $this->item_homedir($item), 'private_homedir' => $this->item_homedir($item, true), 'controller' => $this, 'form' => $this->form, 'form_fields' => $this->filtered_form_fields); foreach ($this->filtered_form_fields as $field => $parms) { $type = CMS_Fields::type($parms); $type->process_uploads($field, $parms, $this->uploaded_files, $item, $uploads_extra); } foreach ($this->uploaded_files as $fdata) { IO_FS::rm($fdata['uplpath']); } }
public function process_inserted($name, $data, $item) { $item_id = $item->id(); $value = trim($item[$name]); if ($value != '') { if ($value[0] == '#') { $uploaded = trim(substr($value, 1)); $value = ''; if ($uploaded != '') { $uploaded = str_replace('..', '', $uploaded); $filename = $uploaded; $uploaded = CMS::temp_dir() . '/' . $uploaded; if (IO_FS::exists($uploaded)) { $ext = ''; if ($m = Core_Regexps::match_with_results('{\\.([^\\.]+)$}', $uploaded)) { $ext = trim($m[1]); } $filename = $this->uploaded_file_name($name, $data, $item, $ext, $filename); $dir = $this->uploaded_file_dir($name, $data, $item); if ($dir) { if (!IO_FS::exists($dir)) { CMS::mkdirs($dir); } $_dir = preg_replace('{^\\./}', '', $dir); copy($uploaded, "{$dir}/{$filename}"); CMS::chmod_file("{$dir}/{$filename}"); IO_FS::rm($uploaded); $value = "{$_dir}/{$filename}"; } } } } } $item[$name] = $value; if (!empty($value) && method_exists($item, 'clear_cache')) { $item->clear_cache(false); } $this->preset->preset_on_upload($this->container($name, $data, $item)); return true; }