无法从MySQL数据库中检索所有图像

时间:2018-02-16 17:20:01

标签: php mysql sql

我正在构建一个简单的网页,我想在其中显示一些位于我的计算机上的图像@ C:\ xampp \ htdocs \ website \ upload 。我已将它们的(相对)路径存储到MySQL数据库中,如下所示: website / upload / filename.extension 。 例如:

const express = require('express');
   
const fetch = require('node-fetch');
const btoa = require('btoa');
const { catchAsync } = require('./utils');
const router = express.Router();
    
const CLIENT_ID = 'CLIENT_ID ';
const CLIENT_SECRET = 'CLIENT_SECRET';
const creds = btoa(`${CLIENT_ID}:${CLIENT_SECRET}`);
const redirect = encodeURIComponent('http://localhost:50451/callback');
    
router.get('/login', (req, res) => {
   res.redirect('https://flow.polar.com/oauth2/authorization?response_type=code&client_id=client_id');
});

router.get('/list', catchAsync(async (req, res) => {
   if (!req.query.code) throw new Error('NoCodeProvided');
      const code = req.query.code;
      const creds = btoa(`${CLIENT_ID}:${CLIENT_SECRET}`);
   
      fetch('https://polarremote.com/v2/oauth2/token', {
         method: 'POST',
         data : {
            'grant_type' : 'authorization_code',
            'redirect_uri' : redirect,
            'code' : code
         },    
         headers : {
            'Authorization':`Basic ${creds}`,
            'Content-Type':'application/x-www-form-urlencoded',
             'Accept':' application/json;charset=UTF-8'
         }
      })
      .then(function(response) {
          return response.json();
          console.log(response.json());
       }).then(function(body) {
           console.log(body); 
           res.send('POST');
       });
 })

应该检索它们的PHP代码是:

INSERT INTO `photos` (`photoid`, `photopath`, `photoname`, `photoyear`) 
VALUES ('20', 'website/upload/Putin.jpg', 'Putin', '2017');

然而,它只返回一张图片并完全忽略其他图片,结果为something like this。如果我从我的数据库中删除该特定图片,它会显示none of the others,尽管它们的位置和文件类型一致。

我能做些什么才能成功显示所有图像? 谢谢!

1 个答案:

答案 0 :(得分:1)

右键单击有错误的图像并打开Inspect Element,检查链接是否正常。如果图像有404,则问题在于您存储的链接。

相关问题