我正在实现一个表单来获取用户的个人详细信息和DP用户的图像。如果数据正确提交,我如何在下一页显示它。如何获取图像并将其显示在下一页上?
-1
A
回答
1
这可以帮助你,
上传表单。
<html>
<head><title>File Upload To Database</title></head>
<body>
<h2>Please Choose a File and click Submit</h2>
<form enctype="multipart/form-data" action="<?php echo htmlentities($_SERVER['PHP_SELF']);?>" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="99999999" />
<div><input name="userfile" type="file" /></div>
<div><input type="submit" value="Submit" /></div>
</form>
</body></html>
上传图片。
<?php
/*** check if a file was submitted ***/
if(!isset($_FILES['userfile']))
{
echo '<p>Please select a file</p>';
}
else
{
try {
upload();
/*** give praise and thanks to the php gods ***/
echo '<p>Thank you for submitting</p>';
}
catch(Exception $e)
{
echo '<h4>'.$e->getMessage().'</h4>';
}
}
?>
上传功能
<?php
/**
*
* the upload function
*
* @access public
*
* @return void
*
*/
function upload(){
/*** check if a file was uploaded ***/
if(is_uploaded_file($_FILES['userfile']['tmp_name']) && getimagesize($_FILES['userfile']['tmp_name']) != false)
{
/*** get the image info. ***/
$size = getimagesize($_FILES['userfile']['tmp_name']);
/*** assign our variables ***/
$type = $size['mime'];
$imgfp = fopen($_FILES['userfile']['tmp_name'], 'rb');
$size = $size[3];
$name = $_FILES['userfile']['name'];
$maxsize = 99999999;
/*** check the file is less than the maximum file size ***/
if($_FILES['userfile']['size'] < $maxsize)
{
/*** connect to db ***/
$dbh = new PDO("mysql:host=localhost;dbname=testblob", 'username', 'password');
/*** set the error mode ***/
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
/*** our sql query ***/
$stmt = $dbh->prepare("INSERT INTO testblob (image_type ,image, image_size, image_name) VALUES (? ,?, ?, ?)");
/*** bind the params ***/
$stmt->bindParam(1, $type);
$stmt->bindParam(2, $imgfp, PDO::PARAM_LOB);
$stmt->bindParam(3, $size);
$stmt->bindParam(4, $name);
/*** execute the query ***/
$stmt->execute();
}
else
{
/*** throw an exception is image is not of type ***/
throw new Exception("File Size Error");
}
}
else
{
// if the file is not less than the maximum allowed, print an error
throw new Exception("Unsupported Image Format!");
}
}
?>
显示图像
<?php
/*** some basic sanity checks ***/
if(filter_has_var(INPUT_GET, "image_id") !== false && filter_input(INPUT_GET, 'image_id', FILTER_VALIDATE_INT) !== false)
{
/*** assign the image id ***/
$image_id = filter_input(INPUT_GET, "image_id", FILTER_SANITIZE_NUMBER_INT);
try {
/*** connect to the database ***/
$dbh = new PDO("mysql:host=localhost;dbname=testblob", 'username', 'password');
/*** set the PDO error mode to exception ***/
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
/*** The sql statement ***/
$sql = "SELECT image, image_type FROM testblob WHERE image_id=$image_id";
/*** prepare the sql ***/
$stmt = $dbh->prepare($sql);
/*** exceute the query ***/
$stmt->execute();
/*** set the fetch mode to associative array ***/
$stmt->setFetchMode(PDO::FETCH_ASSOC);
/*** set the header for the image ***/
$array = $stmt->fetch();
/*** check we have a single image and type ***/
if(sizeof($array) == 2)
{
/*** set the headers and display the image ***/
header("Content-type: ".$array['image_type']);
/*** output the image ***/
echo $array['image'];
}
else
{
throw new Exception("Out of bounds Error");
}
}
catch(PDOException $e)
{
echo $e->getMessage();
}
catch(Exception $e)
{
echo $e->getMessage();
}
}
else
{
echo 'Please use a real id number';
}
?>
如果你需要的任何其他信息,您canrefer此链接:
http://www.phpro.org/tutorials/Storing-Images-in-MySQL-with-PHP.html
+0
谢谢Shivam .... –
+0
没关系,请接受这个答案。 – Shivam
1
传递页面之间的值有很多方法。
- 存储会话和使用下一页。如果不使用,则稍后删除该会话
- 如果您使用Ajax表单发布获取详细信息,则事情更简单。获取详细信息并存储在会话中或任何隐藏的表单参数。发布到下一页。
相关问题
- 1. 如何将图像保存到localStorage并将其显示在下一页上?
- 2. 如何从SD卡上获取图像并将其显示在屏幕上?
- 3. 如何获取用户在表单中选择的多个图像并将其显示在下一页中?
- 4. 如何变暗网页并在其上显示另一个网页(附图像)?
- 5. 使用UIPopover从图库获取图像并将其显示
- 6. 如何获取按钮的值并将其显示在edittext上?
- 7. 如何从网上下载图像并将其显示在UIImageView中?
- 8. 如何从xml Ip api获取xml内容并将其显示在网页上?
- 9. 如何获取页面浏览量并将其显示在Rails应用上?
- 10. 如何从其他网页获取图片并在我的网站上显示
- 11. 如何从iOS照片库中获取图像并将其显示在UIWebview中
- 12. 如何在网页上显示像图像一样的图像
- 13. 从数据库获取图像并将其显示在屏幕上
- 14. 如何在相机显示屏上显示PNG图像并使其显示在图像上?
- 15. 如何捕捉网站上的图像,并在其他网页上显示
- 16. 如何从Web上加载图像,并在获取某些数据后立即将其显示在视图中
- 17. 如何获取img alt标签并将图像显示为html?
- 18. 如何显示从android下载并显示一个Bitamp图像?
- 19. 从URL下载图像并将其显示在GridView中
- 20. 从一个页面获取信息并在其他页面上显示
- 21. 如何从数组中获取图像并将其显示在桌面视图上
- 22. 从外部存储器获取图像并将其显示在图库中
- 23. 如何上传图像并在asp.net中显示在同一页上mvc 4
- 24. 从位图工厂获取图像信息并显示在页面上
- 25. 提取数据库内容并将其显示在网页上
- 26. 我如何获取数据以显示在其他页面上?
- 27. 如何从oracle sql检索图像并将其显示在jsp页面中?
- 28. 如何下载图像并将其显示在NativeScript应用程序中?
- 29. 如何渲染POST并使其显示在另一页上
- 30. Java在彼此上显示图像并将其移动到
你保存它时,表单被提交,并在您检索时提交想展示它。如需更具体的回复,请提出更具体的问题(代码?)。 – CompuChip