我正在我的网站上使用wordpress查看并更改用户的封面,点击照片,然后将其重定向到例如process.php?pid=12
我正在使用
switch($GetPicId)
{
所以我无法添加更多图片,但现在我有使用数据库上传图片的脚本,我想通过使用数据库获取id和pic位置
首先这是upload script
这是切换代码
$GetPicId = $_GET["pid"]; // Picture ID from Index page
$PicLocation ='';
/*
Users do not need to know original location of image.
I think it's better to get image location from database using ID.
for demo here i'am using PHP switch.
*/
switch($GetPicId)
{
case 1:
$PicLocation = 'cover_pics/cover1.jpg';
break;
case 2:
$PicLocation = 'cover_pics/cover2.jpg';
break;
case 3:
$PicLocation = 'cover_pics/cover3.jpg';
break;
case 4:
$PicLocation = 'cover_pics/cover4.jpg';
break;
case 5:
$PicLocation = 'cover_pics/cover5.jpg';
break;
case 6:
$PicLocation = 'cover_pics/cover6.jpg';
break;
case 7:
$PicLocation = 'cover_pics/cover7.jpg';
break;
case 8:
$PicLocation = 'cover_pics/cover8.jpg';
break;
case 9:
$PicLocation = 'cover_pics/cover9.jpg';
break;
case 10:
$PicLocation = 'cover_pics/cover10.jpg';
break;
case 11:
$PicLocation = 'cover_pics/cover11.jpg';
break;
default:
header('Location: ' . $homeurl);
break;
}
答案 0 :(得分:0)
使用它来获取附件网址。您的封面图片是否已上传到媒体中?
然后试试这个
<?php wp_get_attachment_url( $id ); ?>
它会变成这样的东西
$GetPicId = $_GET["pid"]; // Picture ID from Index page
$PicLocation =wp_get_attachment_url( $GetPicId);
答案 1 :(得分:0)
试试
$GetPicId = $_GET["pid"]; // Picture ID from Index page
$sql=mysql_query("SELECT piclocation FROM tableName WHERE pid=$GetPicId") or die(mysql_error());
$res=mysql_fetch_array($sql);
$PicLocation = $res['piclocation '];