File extension check fails

Hi all!
Im uploading files to my server and i want to put the video files and image files in different locations, so i made script to check the files extension and set the upload dir accordingly.
The problem is that if i upload sample.avi it puts it in the image dir.

[code]<?php
session_start();
header(‘P3P: CP=“IDC DSP COR CURa ADMa OUR IND PHY ONL COM STA”’);

$file_count = count ($FILES[“file”][“name”]);
for ($i=0; $i < $file_count; $i++) {
$fname = str_replace (" ", "
", $_FILES[“file”][“name”][$i]);
$ftype = strrchr ($fname, ‘.’);
$fsize = $_FILES[“file”][“size”][$i];
$ftemp = $_FILES[“file”][“tmp_name”][$i];

echo $fname;
echo $ftype;
echo $fsize;
echo $ftemp;

if ($ftype = ".jpg" | $ftype = ".jpeg" | $ftype = ".png" | $ftype = ".gif") {
	$uploadtarget = "/var/www/insite/resources/images/";
	$uploadfile = $uploadtarget.$fname;
	$redirect = "../home.php?body=image.php";
	if (move_uploaded_file ($ftemp, $uploadfile)) {
		echo "<div align='center'>Upload successful</div>";
	}	
	else {			
		echo "<div align='center'>Upload failed</div>";
	}		
}
elseif ($ftype = ".avi" || $ftype = ".mkv") {
	$uploadtarget = "/var/www/insite/resources/videos/";
	$uploadfile = $uploadtarget.$fname;
	$redirect = "../home.php?body=videos.php";
	if (move_uploaded_file ($ftemp, $uploadfile)) {
		echo "<div align='center'>Upload successful</div>";
	}	
	else {
		echo "<div align='center'>Upload failed</div>";
	}
}

}
header (“refresh: 3; url=$redirect”);
?>[/code]

Strange this is that when uploading sample.avi the $ftype output is correctly .avi.
So what i going wrong here? Im out of ideas!

Here you have assignment, but it supposed to be comparison:
[php] if ($ftype = “.jpg” | $ftype = “.jpeg” | $ftype = “.png” | $ftype = “.gif”) {[/php]
correct is:
[php] if ($ftype == “.jpg” | $ftype == “.jpeg” | $ftype == “.png” | $ftype == “.gif”) {[/php]

and same problem is here:
[php] elseif ($ftype = “.avi” || $ftype = “.mkv”) {[/php]

Thanks allot! Thats a really stupid newbie mistake :-[ , as youve noticed this is my first week of php :P.

Thanks for the help!

Sponsor our Newsletter | Privacy Policy | Terms of Service