Tjobbe
June 28th, 2007, 16:15
Basically, I have a php script that takes form data and stores information into a mysql database, and uploads an image into a folder.
Currently, if no image is uploaded, then the script breaks, I'd like it to carry on, and enter a blank image that is already uploaded, into the database.
Here's the php;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Patrick Lennon Associates - Marketing and public relations consultants</title>
<link rel="stylesheet" type="text/css" href="/style/style.css" />
</head>
<body>
<div id="all">
<div id="box" class="clearfix">
<div id="header">
<ul>
<li><a id="homeLink" href="/cms/">Admin Home</a></li>
</ul>
</div>
<div id="content">
<?php
include "dbconnect.php"; $uploaddir = '../images/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "<h1>Image and article successfully stored</h1>";
$title=$_POST['title'];
$shortdescr=$_POST['shortdescr'];
$source=$_POST['source'];
$content=$_POST['content'];
$date=$_POST['date'];
$category=$_POST['category'];
$image= basename($_FILES['userfile']['name']);
$sqlquery = "INSERT INTO $category VALUES (id,'$title','$shortdescr','$source','$content','$ date','$image')";
$results = mysql_query($sqlquery) or die(mysql_error());
} else {
echo "Possible file upload attack!\n";
}
echo "<br /><img style=\"float:right; padding: 0 10px 0 10px;\" src=\"/cms/images/$uploadfile\" />";
echo "<p><strong>$title</strong></p>";
echo nl2br("$content");
?>
<p><a href="/cms/"><img src="/cms/images/backbutton.jpg" alt="Back to the admin home page" width="194" height="101" border="0" /></a></p>
</div>
<div id="footer">
<?php include '/includes/footer.php'; ?>
</div>
</div>
</div>
</body>
</html>
What do I need to do to tell the script to use the blank image already stored on the folder on the server, to use thta if no image has been uploaded?
Currently, if no image is uploaded, then the script breaks, I'd like it to carry on, and enter a blank image that is already uploaded, into the database.
Here's the php;
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Patrick Lennon Associates - Marketing and public relations consultants</title>
<link rel="stylesheet" type="text/css" href="/style/style.css" />
</head>
<body>
<div id="all">
<div id="box" class="clearfix">
<div id="header">
<ul>
<li><a id="homeLink" href="/cms/">Admin Home</a></li>
</ul>
</div>
<div id="content">
<?php
include "dbconnect.php"; $uploaddir = '../images/';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo "<h1>Image and article successfully stored</h1>";
$title=$_POST['title'];
$shortdescr=$_POST['shortdescr'];
$source=$_POST['source'];
$content=$_POST['content'];
$date=$_POST['date'];
$category=$_POST['category'];
$image= basename($_FILES['userfile']['name']);
$sqlquery = "INSERT INTO $category VALUES (id,'$title','$shortdescr','$source','$content','$ date','$image')";
$results = mysql_query($sqlquery) or die(mysql_error());
} else {
echo "Possible file upload attack!\n";
}
echo "<br /><img style=\"float:right; padding: 0 10px 0 10px;\" src=\"/cms/images/$uploadfile\" />";
echo "<p><strong>$title</strong></p>";
echo nl2br("$content");
?>
<p><a href="/cms/"><img src="/cms/images/backbutton.jpg" alt="Back to the admin home page" width="194" height="101" border="0" /></a></p>
</div>
<div id="footer">
<?php include '/includes/footer.php'; ?>
</div>
</div>
</div>
</body>
</html>
What do I need to do to tell the script to use the blank image already stored on the folder on the server, to use thta if no image has been uploaded?