示例#1
0
    }
    public function save()
    {
        $data = $this->cleaned_data();
        $image_path = $data['image']->move_to($this->path);
        // do something with the data like saving it to a database...
        return $image_path;
    }
}
// Init form
$form = new UploadForm('/tmp', Phorm::POST, true);
// If the form is bound and valid, move the file to a more permanent location
$saved = null;
$file_error = null;
$photo_path = null;
if (($valid = $form->is_valid()) && $form->is_bound()) {
    try {
        $photo_path = $form->save();
        $saved = true;
    } catch (Exception $e) {
        $file_error = $e->message;
    }
}
?>
<html>
	<body>
		<style>
			table { border: 1px solid #ccc; padding: 2px 4px; }
			th { vertical-align: top; text-align: right; }
			td { vertical-align: top; }
			thead th { text-align: center; font-size: 16pt; background-color: #ccc; }
示例#2
0
        $image_path = $data['image']->move_to($this->path);
        // do something with the data like saving it to a database...
        return $image_path;
    }
    public function report()
    {
        var_dump($this->cleaned_data());
    }
}
// Init form
$form = new UploadForm(UPLOAD_TARGET_DIRECTORY, 'post', TRUE);
// If the form is bound and valid, move the file to a more permanent location
$saved = NULL;
$file_error = NULL;
$photo_path = NULL;
if (($valid = $form->is_valid()) && $form->bound) {
    try {
        $photo_path = $form->save();
        $saved = TRUE;
    } catch (Exception $e) {
        $file_error = $e->message;
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
	<head>
		<title>Image Upload Form example for Phorm</title>
		<link rel="stylesheet" href="assets/style.css" type="text/css" />
	</head>