TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
 
 
LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
Old 05-28-2008, 08:54 AM   #1 (permalink)
Jmz
The Acquainted
 
Join Date: Oct 2007
Location: Newcastle, UK
Posts: 113
Thanks: 3
Jmz is on a distinguished road
Default 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?
__________________
Free CSS Tutorials
Send a message via MSN to Jmz
Jmz is offline  
Reply With Quote
 



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 12:02 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design