php - 我如何设置默认默认图像 (no_pic.gif) php?

标签 php mysql default

我在项目中的图片中有一个默认图像,但似乎无法在用户未上传图像时反射(reflect)出来。请帮助。下面是个人资料 View 和上传脚本

配置文件.php:

<head>
        <title>Profile</title>
    </head>
    <body>
        <table>
            <tr>
                <td colspan="2">View Your Current Profile</td>
            </tr>
             <tr>
                <td>Title:</td>
                <td><?php echo $jobseekertitle; ?></td>
            </tr>
             <tr>
                <td>First Name:</td>
                <td><?php echo $jobseekerfirstname; ?></td>

            </tr>
             <tr>
                <td>Last Name:</td>
                <td><?php echo $jobseekerlastname; ?></td>
            </tr>
             <tr>
                <td>Address:</td>
                <td><?php echo $jobseekeraddress; ?></td>
            </tr>
             <tr>
                <td>Phone:</td>
                <td><?php echo $jobseekerphoneno; ?></td>
            </tr>
             <tr>
                <td>D.O.B (mm/dd/yyyy):</td>
                <td><?php echo $jobseekerdob; ?></td>
            </tr>
             <tr>
                <td>Gender:</td>
                <td><?php echo $jobseekergender; ?></td>
            </tr>
             <tr>
                <td>Picture:</td>

                <td><?php echo "<img src='$location' width='100' height='100'>";?></td>
            </tr>
        </table>

        <br><a href='upload.php'> Image upload</a>

        <br><a href='resumecreator.php'> Resume information</a>

         <br><a href='jobpreference.php'> Job Preference</a>

</body>
</html>

上传.php

<?php
// form in which we can upload the image
session_start();

include("connect.php");

// session as on website.

$jobseekerid = $_SESSION['jobseekerid'];

if($_POST['submit'])
{
    //get file attributes
    $name = $_FILES['myfile']['name'];
    $tmp_name = $_FILES['myfile']['tmp_name'];


    if ($name)
    {
       // start upload process
       $location ="pictures/$name";
       move_uploaded_file($tmp_name,$location);
// updating table users (setting image locaion
       $query = mysql_query("UPDATE jobseekers SET imagelocation='$location' WHERE jobseekerid='$jobseekerid'");

       die("Your avatar has been uploaded! <a href='profile.php'>Go back to view</a>");


    }
    else

        die("Please Select a file!");

}

echo "Welcome, ".$_SESSION['username']."!<br><a href='logout.php'>Logout</a>";

echo "Upload Your image:

<form action='upload.php' method='POST' enctype='multipart/form-data'>
File: <input type='file' name='myfile'> <input type='submit' name='submit' value='upload!'
>
</form>

";

?>

最佳答案

我一般都是这样

<td><img src="<?= @$location ? $location : 'default/image.gif' ?>" width="100" height="100" /></td>

这样,如果 $location 不存在,它会抑制错误并输出默认替换。

关于php - 我如何设置默认默认图像 (no_pic.gif) php?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5111682/

相关文章:

php - 如何修复 PHP : "A non well formed numeric value encountered" 中的此错误

javascript - 离线使用谷歌地球(或 map )

php - MySQL PDO - 如何处理字段名称中的问号

c# - 使用 default 作为可为 null 的值类型参数的默认值不会分配 null

python argparse,如果省略选项则搜索特定文件

php - Sylius-标准管理面板 : no css/js

php - 如何从两个不同的表中按两个不同的类别有条件地排序

php - MYSQL 查询在 1 个查询中包含我需要的 2 个内容

mysql - 在 JOIN 上排除 MySQL 中的结果

PHP 定义一个变量,如果它没有传递给函数