【问题标题】:How do I show the resulting image after a php upload?php 上传后如何显示生成的图像?
【发布时间】:2017-03-18 13:17:52
【问题描述】:

我正在尝试显示上传的图像及其使用此代码处理后的 url,但我有点坚持如何实现这一点,而不是返回“完成...”的页面

http://llngg6czd-site.1tempurl.com/tester/index.php

索引.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

任何帮助将不胜感激。

【问题讨论】:

    标签: php forms upload image-uploading


    【解决方案1】:

    你把文件另存为

    'uploads/' . $newNamePrefix . $_FILES['image']['name']
    

    因此,您可以通过返回带有“src”属性的 IMG-Tag 来简单地显示它:

    echo '<img src="./uploads/' . $newNamePrefix . $_FILES['image']['name'] . '">';
    

    【讨论】:

      猜你喜欢
      • 2011-04-13
      • 2021-08-14
      • 2014-05-23
      • 1970-01-01
      • 2016-01-04
      • 1970-01-01
      • 1970-01-01
      • 2018-02-21
      • 1970-01-01
      相关资源
      最近更新 更多