PDA

View Full Version : PHP Image uploading.



TechnoPanda
05-06-2009, 08:56 PM
<?php
session_start();
// Admin Section
if($_SESSION['status'] != 2){die('You must be an administrator to access this section; please <a href="login.php">login</a>');}
require ("connect.php");
require("functions.php");
include("template/header.php");
$errorMsg = "";
if(!empty($_POST['submit']))
{
$title = mysql_real_escape_string($_POST['title']);
$link = mysql_real_escape_string($_POST['link']);
$cat = mysql_real_escape_string($_POST['cats']);
if(empty($title)|| empty($link) || empty($cat)){$errorMsg = " --- <b><u>All required(*) fields must be filled in!</u></b>";}
else
{
$rand = rand(0,999999);
$image = empty($_FILES["file"]["name"]) ? "none.jpeg" : "$rand" . $_FILES["file"]["name"];
if($image != "none.jpeg"){move_uploaded_file($_FILES["file"]["tmp_name"], $image);}
mysql_query("INSERT into layouts VALUES(NULL, '$title', '$link', '$image', '0', '$cat')") or die(mysql_error());
echo "The layout has been created! - $image";
die();
}
}
echo "<a href=\"admin.php\">Return to admin section!</a></br><br/><br/>
Here you can add layouts. If you wish to add a category, please go to <a href='admin-cats.php'>this</a> section!<br/><br/>
Create a new layout:<span style='color:#f00;'>$errorMsg</span>
<form action='#' method='post' enctype='multipart/form-data'>
<table>
<tr><td align='right'>Title: </td><td><input type='text' name='title' value='".$_POST["title"]."'> <span style='color:#f00;font-weight:bold;'>*</span></td></tr>
<tr><td align='right'>Link to the layout: </td><td><input type='text' name='link' value='".$_POST["link"]."'> <span style='color:#f00;font-weight:bold;'>*</span></td></tr>
<tr><td>Display image (100px x 100px): </td><td><input id='file' type='file' name='file'/></td></tr>
<tr><td colspan='2'>";listcats();echo "</td></tr>
<tr><td colspan='2' align='center'><br /><input type='submit' name='submit' value='Create layout!'></td></tr>
</table>
</form>";
include("template/footer.php");
?>

The code above uploads a file and puts the filename into the database into a field called image. I would like it so I can upload another image and that filename goes into another field called thumbnail.

How would I do that?

Protege
06-06-2009, 06:13 AM
You use the file already uploaded, size it down to create the "thumbnail", you can then move it and put it into another location then query the DB.

Want to hide these adverts? Register an account for free!