Welcome toVigges Developer Community-Open, Learning,Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
407 views
in Technique[技术] by (71.8m points)

保存到数据库中的图片只有名称,Ajax获取PHP返回只有图片名称,无法获取到图片

将数据存入数据库PHP:
<?PHP
    header("Content-Type: text/html; charset=utf-8");
    include('conn.php');//链接数据库
    //1、设置变量来接收表单提交过来的值
    $article_name = $_POST['art_name'];
    $checkbox = $_POST['checkbox'];
    $content = $_POST['content'];
    $input_name = $_POST['input_name'];
    $input_number = $_POST['input_number'];
    $input_ewm = $_POST['input_ewm'];
    $input_title = $_POST['input_title'];
    $input_describe = $_POST['input_describe'];
    $input_image = $_POST['input_image'];
    //2、将数组转为字符串
    $check_box=implode(',',$checkbox);
    //3、插入到数据库
    $sql="insert into article(id,article_name,check_box,radio_box,content,input_name,input_number,input_ewm,input_title,input_describe,input_image) values(null,'$article_name','".$check_box."','$_POST[radio_box]','$content','$input_name','$input_number','$input_ewm','$input_title','$input_describe','$input_image')";
    $result = mysqli_query($conn,$sql);
    echo $sql;
?>

input_ewm和input_image是图片,我是直接post上传的图片,然后保存到数据库中,存进去的是图片的名称,貌似没有图片,因为我后面ajax取得php的返回值是图片的名称,$("#前端id").attr("src",data[在数组中的序号,从0开始]);输出显示的时候,提示图片:
GET http://ceshi.xxx.com/ceshi.jpg 404 (Not Found)
GET http://ceshi.xxx.com/ceshi2.jpg 404 (Not Found)
其他checkbox和ridaobox都能取到,就是查不到图片,我该怎么修改能够让图片能够被获取到,而不是404找不到图片?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
  1. 打开chrome的network检查post接口的数据,发给后端的是图片文件还是图片名称?
  2. 后端接收到图片文件后,是要保存再服务器(或上传到第三方存储服务)的
  3. 存储到数据库的图片地址应该是一个http或https协议的完整地址

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to Vigges Developer Community for programmer and developer-Open, Learning and Share
...