我有一个显示图像的目录:
<img src="(image path)" style="width:304px;height:228px">
如何使用PHP获取图像路径?
我还想检查目录是否存在,我得到图像路径,如果没有显示错误。
如果我得到图像路径,我想使用HTML显示图像:
class MonsterNode: GameObjectNode {
var monsterType: MonsterType!
let monsterSound = SKAction.playSoundFileNamed("MONSTER.mp3", waitForCompletion: false)
override func collisionWithPlayer(player: SKNode) -> Bool {
if player.physicsBody?.velocity.dy < 0 {
runAction(monsterSound, completion: {
})
player.physicsBody?.velocity = CGVector(dx: player.physicsBody!.velocity.dx, dy: 450.0)
self.removeFromParent()
} else if player.physicsBody?.velocity.dy > 0 {
player.physicsBody?.velocity = CGVector(dx: -player.physicsBody!.velocity.dx, dy: -450.0)
player.hidden = true
}
return false
}
答案 0 :(得分:0)
假设您将图像路径转换为变量&gt; $ IMAGE_PATH
只需这样做......
<img src="<?php echo $image_path; ?>" style="width:304px;height:228px">
答案 1 :(得分:0)
http://php.net/manual/en/function.file-exists.php
<?php
$file = "C:\myfile.jpg";
if(file_exists($file)){
if(is_readable($file)){
echo '<img src="'.$file.'">';
}
}
else
{
// UNABLE TO FIND FILE;
}
?>
答案 2 :(得分:0)
亲爱的雷克斯这样做,
<?php
$path = "www/item";
$folder = opendir($path);
$pic = false;
while(false !== ($file = readdir($folder))){
$fileName = $path.$file;
$info = pathinfo($path.$file);
$ext = strtolower($info['extension']);
$allowed =array("jpg","bmp","png","gif");
if(filetype($fileName) == "file"){
if(in_array($ext,$allowed)){
echo"
<div style='display:inline-block'>
<img src='$fileName' style='width:96px;height:70px;' title='Filename: $file'>
<a target = '_blank' href='$fileName'>Download</a>
</div>
";
$pic = true;
}
}
}
if($pic == false){
echo "There are no images in $path";
}
?>