Jump to content

FileExists with Partial String


doubledee

Recommended Posts

There are a number of false positives in there... Pay attention to the ones involving glob().

 

Have any better ideas then?

 

Here is a snippet of my code...

// ********************
// Hash New Image.		*
// ********************
$newFilename = sha1_file($tempFile);

if (!$newFilename){
	// Hashing Failed.
	$_SESSION['resultsCode'] = 'UPLOAD_HASH_IMAGE_FAILED_2119';

	// Redirect to Outcome Page.
	header("Location: " . BASE_URL . "members/results.php");

	// End script.
	exit();
}


// ************************
// Create New File Path.	*
// ************************
$newFilePath = WEB_ROOT . 'uploads/' . $newFilename;


// ************************
// Check New File Exist.	*
// ************************
if (file_exists(WEB_ROOT . 'uploads/' . 'f21190299a795e9cf3439f7f62c223f79e023ab7.jpg')){
	echo 'TRUE';
	exit();
}

// ********************
// Create New Image.	*
// ********************
// New File to have same File-Type as Original File.
switch ($imageType){
	case 'image/gif':
		$newThumbnail = @imagegif($newImage, $newFilePath . '.gif');
		break;

	case 'image/jpeg':
		$newThumbnail = @imagejpeg($newImage, $newFilePath . '.jpg');
		break;

	case 'image/png':
		$newThumbnail = @imagepng($newImage, $newFilePath . '.png');
		break;

	default:
		$newThumbnail = FALSE;
}

 

I am trying to see if a Photo already exists based on the Filename BEFORE the Extension, because after I have calculated the appropriate Extension, then a NEW Photo has been generated.

 

I create the "Filename" regardless, because I'll need that when I run an UPDATE on the User's Record.

 

(I'm sure there is a better overall way to do this, but it is my first attempt at things.

 

Hope that makes sense?!

 

Thanks,

 

 

Debbie

 

Link to comment
Share on other sites

Actually, this is NOT necessarily true.

 

I am trying to see if a Photo already exists based on the Filename BEFORE the Extension, because after I have calculated the appropriate Extension, then a NEW Photo has been generated.

 

It is quite easy to create a new name for a file/image BEFORE you actually create/save/rename the file/image. AND as we all know 12345.jpg and 12345.png are considered to be a completely different files.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.