Jump to content

[SOLVED] $ext['filename'] messing up everything... please help me


clown[NOR]

Recommended Posts

well... I'm making a picture uploader that only accepts filenames named "logo.gif"... but there must be something wrong cuz even when I upload a file named logo.gif it gives me the "Filename must be logo" error message.

 

<?php

include('../../../config/main.php');

session_start();

$logoFile = basename($_FILES['uploadlogo']['name']);
$logoPath = "../../../images/";
$logoFullPath = $logoPath . $logoFile;
if (move_uploaded_file($_FILES['uploadlogo']['tmp_name'], $logoFullPath)) {

	chmod($logoFullPath, 0777);
	$ext = pathinfo($logoFullPath);
	if ($ext['basename'] !== "logo.gif") {
		$_SESSION['cngState'] = "The image MUST be named logo.gif";
		Header("Location: $shpUrl");
		unlink($logoFullPath);
	}
	elseif ($ext['extension'] !== "gif") {
		$_SESSION['cngState'] = "The file type MUST be gif";
		Header("Location: $shpUrl");
		unlink($logoFullPath);
	}
	elseif ($ext['filename'] !== "logo") {
		$_SESSION['cngState'] = "The filename MUST be logo";
		Header("Location: $shpUrl");
		unlink($logoFullPath);
	} else {
		$_SESSION['cngState'] = "Your new logo has been succsessfully uploaded.";
		Header("Location: $shpUrl");
	}

}

?>

try

<?php
if (strtolower($ext['basename']) != "logo.gif") {
		$_SESSION['cngState'] = "The image MUST be named logo.gif";
		Header("Location: $shpUrl");
		unlink($logoFullPath);
	}

?>

Note the !== changed to !=

 

also i conveted to lowercase

 

i would also add an echo strtolower($ext['basename']) and comment out the header after just so you can see what your getting

i just replaced all of them witht the one you got... cuz I didn't need to check every section of the filename =) all the script needs to know is if the file is named "logo.gif" or not =) hehe... so all the other codes was just waste of time =)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.