如何将css类应用于上传的图像?

时间:2014-09-21 08:28:21

标签: php css

假设我的代码类标记工作正常:

<img src="img/group2.jpg" class="findface" />

现在,当我通过给定代码上传文件并显示它时:

<?php
$target_path = "./";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)){
echo'<img src="'.$target_path.'" />';
}
?>      
<body>
<form enctype="multipart/form-data" action="<?php $_PHP_SELF ?>" method="POST">
<input type="hidden" name="file" value="upload file" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
</body>

它显示正确,但没有应用类,当我尝试下面的代码时显示错误。任何解决方案?请帮助。所以我可以为每个上传的图像应用类代码以及在浏览器中显示文件。

echo'<img src="'.$target_path.'" /> class="findface";

2 个答案:

答案 0 :(得分:1)

而不是

echo'<img src="'.$target_path.'" /> class="findface";

尝试

echo "<img src='".$target_path."' class='findface' />";

答案 1 :(得分:0)

有拼写错误

echo '<img src="'.$target_path.'" class="findface">';