Example #1
0
/**
 * Gets information about a specific file, whether it was uploaded in the POST
 * body of the current request or in the asynchronous upload session identified
 * by the given ID.
 * 
 * If no such file was received, if an empty file was received, or if there was
 * an error in receiving or storing the file or if it was rejected by PHP,
 * <code>null</code> will be returned.
 * 
 * If an asynchronous upload session ID is given, but no session with that ID
 * actually exists, a notice is triggered.
 * 
 * @param string $name the form field name under which the file was submitted
 * @param string $async_session_id the ID for the asynchronous upload session
 * @param boolean $clear if true, and the uploaded file is found in the
 *        asynchronous session, the file's record will be removed from the
 *        session
 * @return UploadedFile information about the uploaded file, or
 *         <code>null</code> if no such file was uploaded or if there was an
 *         error in uploading it
 */
function reason_get_uploaded_file($name, $async_session_id = null, $clear = false)
{
    if ($async_session_id) {
        $async_session = _get_async_upload_session($async_session_id);
        if ($async_session) {
            if (isset($async_session['files'][$name])) {
                $records = $async_session['files'][$name];
                if (is_array($records) && count($records) > 0) {
                    $keys = array_keys($records);
                    $key = $keys[count($keys) - 1];
                    $async_file = $records[$key];
                    $file = _uploaded_file_from_async($async_file);
                    if (!$file || $clear) {
                        unset($async_session['files'][$name][$key]);
                        $session =& get_reason_session();
                        $id = $async_session_id;
                        $session->set(_async_upload_session_key($id), $async_session);
                    }
                    if ($file) {
                        return $file;
                    }
                }
            }
        } else {
            trigger_warning("tried to get the file {$name} from asynchronous " . 'upload session ' . var_export($async_session_id, true) . ', but ' . 'no such session exists');
        }
    }
    return isset($_FILES[$name]) ? _uploaded_file_from_php($_FILES[$name]) : null;
}
Example #2
0
		'size' => $filesize
	);
	
	if ($img_info) {
		$response[$name]['dimensions'] = array(
			'width' => $width,
			'height' => $height
		);
		$response[$name]['orig_dimensions'] = array(
			'width' => $orig_width,
			'height' => $orig_height
		);
	}
}

$reason_session->set(_async_upload_session_key($upload_sid), $session);
final_response(200, $response);


function check_constraints($constraints, $file) {
	$path = $file->get_temporary_path();
	
	if (!empty($constraints['mime_types'])) {
		if (!$file->mime_type_matches($constraints['mime_types'])) {
			final_response(415, "File is not of an allowed type.");
		}
	}
	if (!empty($constraints['extensions'])) {
		$filename_parts = explode('.', $file->get_filename());
		$extension = strtolower(end($filename_parts));
		if (!in_array($extension, $constraints['extensions'])) {