我在項目中的圖片中有一個默認圖像,但似乎無法讓它反映出用戶何時未上傳圖像。請幫助。下面是縱斷面圖,並上傳腳本如何設置默認的默認圖像(no_pic.gif)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的
<?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>
";
?>
當我需要顯示圖像的東西,我檢查數據庫圖像列,如果長度小於一定的數字我的服務器代碼應用佔位符圖像,否則圖像在數據庫中。 – 2011-02-24 23:10:35