function save_uploaded_image($key, $path) { if (substr($path, -1) == '/') { $filename = save_uploaded_file($key, $path); if (substr($filename, -4) == '.gif') { $filename = gif_to_png($filename); } return $filename; } else { return save_uploaded_file($key, $path); } }
$project = isset($_GET['project']) ? $_GET['project'] : 'test'; if (!is_dir('./projects/' . $project)) { $old_umask = umask(0); mkdir('./projects/' . $project, 0777); umask($old_umask); } if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] == 'GET') { if (isset($_GET['download']) && $_GET['download'] == true) { download_as_zip($project); } else { return_files($project); } } if (isset($_GET['upload']) && $_GET['upload'] == true) { save_uploaded_file($project); } else { if (isset($_GET['delete']) && $_GET['delete'] == true) { delete_file($project); } } // copy&pasted from http://php.net/manual/en/features.file-upload.php function save_uploaded_file($project) { $max_filesize = 500 * 1024 * 1024; try { $file = $_FILES['file']; if (!isset($file['error'])) { throw new RuntimeException('File not defined.'); } if (is_array($file['error'])) {
/** */ function _insert_or_update_item_attributes($item_id, $instance_no, $s_item_type, $s_attribute_type, $order_no, $attribute_val_r, $file_r = NULL) { $is_lookup_attribute_type = is_lookup_attribute_type($s_attribute_type); $attribute_val_r = validate_attribute_val_r($attribute_val_r, $is_lookup_attribute_type); // if not instance item attribute, then discard the $instance_no if (!is_instance_item_attribute_type($s_item_type, $s_attribute_type)) { $instance_no = NULL; } $is_file_resource_attribute_type = is_file_resource_attribute_type($s_attribute_type); if (db_query("LOCK TABLES item_attribute WRITE, item_attribute AS ia READ, s_attribute_type AS sat READ")) { $item_attribute_type_rs = fetch_arrayof_item_attribute_rs($item_id, $instance_no, $s_attribute_type, $order_no); // if same number of attributes, then we can perform an update only. if (count($item_attribute_type_rs) > 0 && count($item_attribute_type_rs) == count($attribute_val_r)) { $op = 'update'; } else { if (count($item_attribute_type_rs) == 0 || delete_item_attributes($item_id, $instance_no, $s_attribute_type, $order_no)) { $op = 'insert'; } else { // if this occurs then the delete_item_attributes function returned FALSE, and that failure would have been logged. db_query("UNLOCK TABLES"); return FALSE; } } // if there is actually something to insert at this point. if (count($attribute_val_r) > 0) { $file_attributes_r = NULL; for ($i = 0; $i < count($attribute_val_r); $i++) { $attribute_no = $i + 1; if ($is_lookup_attribute_type) { if ($op == 'insert') { insert_item_attribute($item_id, $instance_no, $s_attribute_type, $order_no, $attribute_no, $attribute_val_r[$i], NULL); } else { if ($item_attribute_type_rs[$i]['lookup_attribute_val'] != $attribute_val_r[$i]) { update_item_attribute($item_id, $instance_no, $s_attribute_type, $order_no, $attribute_no, $attribute_val_r[$i], NULL); } } } else { if ($is_file_resource_attribute_type) { if (is_array($file_r) && is_uploaded_file($file_r['tmp_name'])) { if ($item_attribute_type_rs[$i]['attribute_val'] != $attribute_val_r[$i] && is_exists_upload_file_item_attribute($attribute_val_r[$i])) { $attribute_val_r[$i] = get_unique_filename($attribute_val_r[$i]); } if (!save_uploaded_file($file_r['tmp_name'], $attribute_val_r[$i])) { $attribute_val_r[$i] = NULL; } $file_attributes_rs[] = array('file_attribute_ind' => 'Y', 'attribute_no' => $attribute_no, 'attribute_val' => $attribute_val_r[$i]); } else { $file_attributes_rs[] = array('attribute_no' => $attribute_no, 'attribute_val' => $attribute_val_r[$i]); } } if (strlen($attribute_val_r[$i]) > 0) { if ($op == 'insert') { insert_item_attribute($item_id, $instance_no, $s_attribute_type, $order_no, $attribute_no, NULL, $attribute_val_r[$i]); } else { if ($item_attribute_type_rs[$i]['attribute_val'] != $attribute_val_r[$i]) { update_item_attribute($item_id, $instance_no, $s_attribute_type, $order_no, $attribute_no, NULL, $attribute_val_r[$i]); } } } } } db_query("UNLOCK TABLES"); if (is_array($file_attributes_rs)) { while (list(, $file_attribute_r) = each($file_attributes_rs)) { file_cache_insert_file($file_attribute_r['attribute_val'], NULL, NULL, NULL, 'ITEM', $file_attribute_r['file_attribute_ind'] == 'Y'); } } } else { db_query("UNLOCK TABLES"); } return TRUE; } else { opendb_logger(OPENDB_LOG_ERROR, __FILE__, __FUNCTION__, db_error(), array($item_id, $instance_no, $s_item_type, $s_attribute_type, $order_no, $attribute_val_r, $file_r)); return FALSE; } }