本文介绍了如何设置默认的默认图片(no_pic.gif)php?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在项目中的图片中有一个默认图片,但是当用户尚未上传图片时,似乎无法反映该图片。请帮助。以下是个人资料视图以及上传脚本

i have a default image in my pictures within the project but cant seem to be able to get it to reflect when user hasn't uploaded an image. Help please. below is the profile view and also the upload script

Profile.php:

Profile.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>

upload.php

upload.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 不存在,它可以消除错误并输出默认替换。

That way if $location does not exist, it suppresses the error and outputs the default replacement.

这篇关于如何设置默认的默认图片(no_pic.gif)php?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 06:13