douzhou7124 2016-07-24 00:38
浏览 42

在网页上显示数据库中的图像

I have been able to upload images into a database but now i would also like to display the uploaded image just below the html form. I am trying to do this by creating an array in a php script that will be used in a separate php script. the error dispalyed is this " Do not access super global $_REQUEST directly" How can i solve this?

<?php

require 'connection';

$id = addslashes ($_REQUEST ['id']);

$image = mysql_query ("SELECT * FROM players WHERE id= $id");
$image2 = mysql_fetch_assoc($image);
$image3 = $image2 ['image'];


header ("content-type: image/jpeg");
echo $image3; 


<?php
require 'connection.php';

// file properties
$id = filter_input(INPUT_POST, 'playerid');
$name = filter_input(INPUT_POST, 'name');
$age = filter_input(INPUT_POST, 'age');
$position = filter_input(INPUT_POST, 'position');
$nationality = filter_input(INPUT_POST, 'nationality');
$file = $_FILES['image']['tmp_name'];

if (! isset($file)){
  echo "Please select an image.";  
}
else {
    $_id = mysql_real_escape_string( $id );
    $_name = mysql_real_escape_string( $name );
    $_age = mysql_real_escape_string( $age );
    $_position = mysql_real_escape_string( $position );
    $_nationality = mysql_real_escape_string( $nationality );
    $image = addslashes(file_get_contents($_FILES ['image']['tmp_name']));
    $image_name = addslashes($_FILES ['image']['name']);
    $image_size = getimagesize($_FILES ['image']['tmp_name']);

 if ($image_size == FALSE){
     echo "Thats not an image.";
 }   
 else{
     if(!$insert = mysql_query("INSERT INTO players  VALUES ( '$_id', '$_name', '$_age', '$_position', '$_nationality', '$image_name', '$image' )" )){
      echo "Problem uploading image.";  
     }
 else
 {
     $lastid = mysql_insert_id();
     echo "Profile photo uploaded.<p />Player photo:<p /><img src= getphoto.php?id=$lastid";
 }
 }
}
  • 写回答

1条回答 默认 最新

  • duangutang3940 2016-07-24 00:47
    关注

    Change

    $id = addslashes ($_REQUEST ['id']);
    

    to access either $_POST or $_GET depending on whether you're handling a POST or GET request:

    $id = addslashes ($_POST['id']);
    or
    $id = addslashes ($_GET['id']);
    
    评论

报告相同问题?

悬赏问题

  • ¥15 如何用Labview在myRIO上做LCD显示?(语言-开发语言)
  • ¥15 Vue3地图和异步函数使用
  • ¥15 C++ yoloV5改写遇到的问题
  • ¥20 win11修改中文用户名路径
  • ¥15 win2012磁盘空间不足,c盘正常,d盘无法写入
  • ¥15 用土力学知识进行土坡稳定性分析与挡土墙设计
  • ¥70 PlayWright在Java上连接CDP关联本地Chrome启动失败,貌似是Windows端口转发问题
  • ¥15 帮我写一个c++工程
  • ¥30 Eclipse官网打不开,官网首页进不去,显示无法访问此页面,求解决方法
  • ¥15 关于smbclient 库的使用