File Uploads (extensions, renaming)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the value in the element will be an integer, not a string. != will make it work.. or using 0 instead of '0'
furiousweebee
Forum Commoner
Posts: 69
Joined: Sun Jul 11, 2004 7:38 am
Location: Brisbane, Australia
Contact:

Post by furiousweebee »

It's all working now, thank you very much to everyone who helped out. Here's my final code:

Code: Select all

$name = $_POST['name'];

if (isset($_POST['enter_data'])) {
	if ($_FILES['fnt']['size'] != '0') {
		$name_short = stripslashes(substr($_POST['name'], 0, 5));
		$extension = strrchr($_FILES['fnt']['name'], ".");
		$filename = $name_short."_".date("d.m.y").$extension;
		$filename = str_replace(" ", "", $filename);
		move_uploaded_file($_FILES['fnt']['tmp_name'], "../images/ads/".$filename);
		$resource = mysql_query("INSERT into sponsors (name, website, description, type, pic) VALUES ('$name', '$website', '$description', '$type', '$filename')") or die(mysql_error()); }
	else {
		$resource = mysql_query("INSERT into sponsors (name, website, description, type, pic) VALUES ('$name', '$website', '$description', '$type', 'n')") or die(mysql_error()); }

MYSQL_CLOSE();
echo"<META HTTP-EQUIV=refresh content=0;URL=index.php>";
	}
Post Reply