Index: src/wp-includes/media.php
===================================================================
--- src/wp-includes/media.php	(revision 46984)
+++ src/wp-includes/media.php	(working copy)
@@ -4295,7 +4295,7 @@
 	}
 
 	$sql = $wpdb->prepare(
-		"SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attached_file' AND meta_value = %s",
+		"SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wp_attached_file' AND BINARY meta_value = %s",
 		$path
 	);
 
Index: tests/phpunit/tests/media.php
===================================================================
--- tests/phpunit/tests/media.php	(revision 46984)
+++ tests/phpunit/tests/media.php	(working copy)
@@ -1058,7 +1058,10 @@
 		$this->assertEquals( $attachment_id, attachment_url_to_postid( $image_url ) );
 	}
 
-	function test_attachment_url_to_postid_schemes() {
+	/**
+	 * @ticket 33109
+	 */
+	function test_attachment_url_to_postid_with_different_scheme() {
 		$image_path    = '2014/11/' . $this->img_name;
 		$attachment_id = self::factory()->attachment->create_object(
 			$image_path,
@@ -1069,13 +1072,29 @@
 			)
 		);
 
-		/**
-		 * @ticket 33109 Testing protocols not matching
-		 */
 		$image_url = 'https://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_path;
 		$this->assertEquals( $attachment_id, attachment_url_to_postid( $image_url ) );
 	}
 
+	/**
+	 * @ticket 39768
+	 */
+	function test_attachment_url_to_postid_should_be_case_sensitive() {
+		$image_path    = '2014/11/' . $this->img_name;
+		$attachment_id = self::factory()->attachment->create_object(
+			$image_path,
+			0,
+			array(
+				'post_mime_type' => 'image/jpeg',
+				'post_type'      => 'attachment',
+			)
+		);
+
+		$image_path = '2014/11/' . ucfirst( $this->img_name );
+		$image_url  = 'http://' . WP_TESTS_DOMAIN . '/wp-content/uploads/' . $image_path;
+		$this->assertNotEquals( $attachment_id, attachment_url_to_postid( $image_url ) );
+	}
+
 	function test_attachment_url_to_postid_filtered() {
 		$image_path    = '2014/11/' . $this->img_name;
 		$attachment_id = self::factory()->attachment->create_object(
