php 上传后如何显示结果图像?
How do I show the resulting image after a php upload?
我正在尝试显示上传的图片,它是 url 在使用此代码处理后,但我对如何实现这一点而不是使用 [= 返回的页面有点困惑27=]
http://llngg6czd-site.1tempurl.com/tester/index.php
Index.php
<!DOCTYPE html>
<html>
<head>
<title>Upload Files using normal form and PHP</title>
</head>
<body>
<form enctype="multipart/form-data" method="post" action="upload_image.php">
<div class="row">
<label for="image">Select a File to Upload</label><br />
<input type="file" name="image" />
</div>
<div class="row">
<input type="submit" value="Upload" />
</div>
</form>
</body>
</html>
image_upload.php
<?php
require_once('ImageManipulator.php');
if ($_FILES['image']['error'] > 0) {
echo "Error: " . $_FILES['image']['error'] . "<br />";
} else {
// array of valid extensions
$validExtensions = array('.jpg', '.jpeg', '.gif', '.png');
// get extension of the uploaded file
$fileExtension = strrchr($_FILES['image']['name'], ".");
// check if file Extension is on the list of allowed ones
if (in_array($fileExtension, $validExtensions)) {
$newNamePrefix = time() . '_';
$manipulator = new ImageManipulator($_FILES['image']['tmp_name']);
// resizing to 200x200
$newImage = $manipulator->resample(200, 200);
// saving file to uploads folder
$manipulator->save('uploads/' . $newNamePrefix . $_FILES['image']['name']);
echo 'Done ...';
} else {
echo 'You must upload an image...';
}
}
Imagemanipulator.php
https://gist.github.com/philBrown/880506
如有任何帮助,我们将不胜感激。
您将文件另存为
'uploads/' . $newNamePrefix . $_FILES['image']['name']
因此,您可以通过返回具有 'src' 属性的 IMG 标签来简单地显示它:
echo '<img src="./uploads/' . $newNamePrefix . $_FILES['image']['name'] . '">';
我正在尝试显示上传的图片,它是 url 在使用此代码处理后,但我对如何实现这一点而不是使用 [= 返回的页面有点困惑27=]
http://llngg6czd-site.1tempurl.com/tester/index.php
Index.php
<!DOCTYPE html>
<html>
<head>
<title>Upload Files using normal form and PHP</title>
</head>
<body>
<form enctype="multipart/form-data" method="post" action="upload_image.php">
<div class="row">
<label for="image">Select a File to Upload</label><br />
<input type="file" name="image" />
</div>
<div class="row">
<input type="submit" value="Upload" />
</div>
</form>
</body>
</html>
image_upload.php
<?php
require_once('ImageManipulator.php');
if ($_FILES['image']['error'] > 0) {
echo "Error: " . $_FILES['image']['error'] . "<br />";
} else {
// array of valid extensions
$validExtensions = array('.jpg', '.jpeg', '.gif', '.png');
// get extension of the uploaded file
$fileExtension = strrchr($_FILES['image']['name'], ".");
// check if file Extension is on the list of allowed ones
if (in_array($fileExtension, $validExtensions)) {
$newNamePrefix = time() . '_';
$manipulator = new ImageManipulator($_FILES['image']['tmp_name']);
// resizing to 200x200
$newImage = $manipulator->resample(200, 200);
// saving file to uploads folder
$manipulator->save('uploads/' . $newNamePrefix . $_FILES['image']['name']);
echo 'Done ...';
} else {
echo 'You must upload an image...';
}
}
Imagemanipulator.php
https://gist.github.com/philBrown/880506
如有任何帮助,我们将不胜感激。
您将文件另存为
'uploads/' . $newNamePrefix . $_FILES['image']['name']
因此,您可以通过返回具有 'src' 属性的 IMG 标签来简单地显示它:
echo '<img src="./uploads/' . $newNamePrefix . $_FILES['image']['name'] . '">';