05-28-2008, 08:54 AM
|
#1 (permalink)
|
|
The Acquainted
Join Date: Oct 2007
Location: Newcastle, UK
Posts: 113
Thanks: 3
|
Change filename on upload
Hi,
I've got a form that lets users upload a thumbnail file. It then puts the filename of the image in the database.
The code looks like:
Code:
<?php
include("../../config/connect.php");
include("../../config/functions.php");
// Where the file is going to be placed
$target_path = "uploads/";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$_FILES['uploadedfile']['tmp_name'];
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
$galleryname = $_POST['galleryname'];
$gallerydescription = $_POST['gallerydescription'];
$gallerykeywords = $_POST['gallerykeywords'];
$thumbname = basename( $_FILES['uploadedfile']['name']);
if (empty ($galleryname) or empty ($gallerydescription) or empty ($gallerykeywords)) {
echo "Fill out all fields";
exit();
}
$galleryname = mysql_real_escape_string($galleryname);
$gallerydescription = mysql_real_escape_string($gallerydescription);
$gallerykeywords = mysql_real_escape_string($gallerykeywords);
$create_gallery = mysql_query("INSERT INTO tbl_gallery (fld_id, fld_galleryname, fld_gallerydesc, fld_keywords, fld_userid, fld_thumbname) values ('', '$galleryname', '$gallerydescription', '$gallerykeywords', '1', '$thumbname')");
if ($create_gallery){
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xmlns:spry="http://ns.adobe.com/spry">
<head>
<title>Settings Updated</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="css/style_notice.css" type="text/css" rel="stylesheet" />
<meta http-equiv="refresh" content="2;url=<?php echo "http://play.jamesowers.co.uk/photo/usercp/create_gallery.php"; ?>"/>
<style type="text/css">
#content {background: #1c284e url(images/logged_out.gif) no-repeat;}
</style>
</head>
<body>
<div id="content">
Gallery Added
</div>
<div id="footer">
<img src="images/logo_login.gif" alt="" class="toplogo"/>
</div>
</body>
<?php
} else {
echo "Error";
}
} else{
echo "There was an error uploading the file, please try again!";
}
?>
I would like to be able to either rename the file or at least add a prefix to the filename (both on the image and in the databse). How would I do this?
Also how would I go about resizing the image if it is over 100px x 100px?
|
|
|