Jump to content

[SOLVED] Upload Type...


phpSensei

Recommended Posts

Can anyone figure out why this message comes up?

 

Invalid file type, refer to the frontpage for the allowed extensions.

 

Even though that the file uploaded is the rigth type.

 

Script

 

<?php
include("templates.php");
$dbhost = "mysql1050.servage.net";
$dbuser = "U4720035";
$dbpass = "P7999620";
$dbname = "U4720035";

$connection = @mysql_connect($dbhost,$dbuser,$dbpass) or die("Website server is currently offline because of the following: " . mysql_error());

if($connection){

mysql_select_db($dbname);


}
else
{

return $connection;

}

//\\<------------- TEMPLATE START ------------->//\\

$header = define("header_1",true);
$css    = define("css",true);
$tail   = define("trail",true);
$home   = define("home",true);
$page   = $_GET['page'];

//\\<------------- HEADER ------------->//\\
print header_1;
print css;


switch($page){

case '':

print home;

break;

case 'home':

print home;

break;

case 'upload':
$filename = $_FILES['file']['name'];
$filesize = $_FILES['file']['size'];
$filetype = $_FILES['file']['type'];
$dir      = "upload/"; 
echo '<table width="230" height="59" border="0" align="center" cellpadding="10" cellspacing="1" bgcolor="#CCCCCC" class="error">
  <tr>
    <td align="center" bgcolor="#FFFFFF" class="error" scope="col">';

if(isset($_POST['upload'])){
if($_POST['posted']=="true"){
    if(($filetype != "image/gif") ||
    ($filetype != "image/jpeg")  || 
    ($filetype != "image/pjpeg")  || 
    ($filetype != "text/plain")   || 
    ($filetype != "application/x-shockwave-flash") || ($filetype != "audio/mp3") ||
    ($filetype != "audio/wav") || 
    ($filetype != "application/octet-stream")){   

  echo 'Invalid file type, refer to the frontpage for the allowed extensions. <br><a href="?page=home">Back</a>'; 
  
  }
      
   
elseif($filesize > 15242880){ 
echo 'File is too large, please refer to the frontpage for more information.'; }
}

elseif(file_exists($dir . $filename)){
echo "step6<br>";
$new = md5($filename);
$file = explode(".",$filename);
$file = $file[0];
$num_rand = rand(2,1000);
$filename = $file[0] . "_" . $file . "_" . $num_rand;
     }
elseif(move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $filename)){ 
			 echo "step4<br>";
			 mysql_query("INSERT INTO upload (file,type,ip) VALUES ('".$filename."','".$filetype."','".$_SERVER['REMOTE_ADDR']."')")or die(mysql_error());
              if($filetype == "image/gif"   || $filetype == "image/jpeg"  || $filetype == "image/pjpeg" ){ 
			  
			  echo 'image'; // image
			  
  
              } 
			elseif( $filetype == "text/plain" || $filetype == "application/octet-stream" ||$filetype == "audio/mp3" ||
                 $filetype == "audio/wav" ){

			 echo 'file'; // files


			 }
                 elseif( $filetype == "application/x-shockwave-flash" ){ 

                 echo 'swf'; // swf
			  
           }
		   else
		   {
		     echo 'uploaded';
		   }
           }
	}
else
{
  echo 'Please Submit the form first.';
  }


echo'</td>
  </tr>
</table>
<br>
<table width="230" height="67" border="0" align="center" cellpadding="1" cellspacing="1" bgcolor="#CCCCCC">
  <tr>
    <td colspan="2" bgcolor="#FFFFFF" scope="col"><table width="100%"  border="0" cellspacing="2" cellpadding="0">
      <tr>
        <td width="24%">Share</td>
        <td width="76%"><input type="text" name="textfield"></td>
      </tr>
      <tr>
        <td>Direct </td>
        <td><input type="text" name="textfield2"></td>
      </tr>
      <tr>
        <td>Emmed</td>
        <td><input type="text" name="textfield3"></td>
      </tr>
    </table>      <div align="center"></div></td>
  </tr>
</table>';
break;

default:

  echo " Bio @ Dude fucking upload with style! .. rofl";

}
//\\<------------- TAIL ------------->//\\
print tail;
//\\<------------- TEMPLATE END ------------->//\\

?>

Link to comment
https://forums.phpfreaks.com/topic/80706-solved-upload-type/
Share on other sites

Using not equal != tests OR'ed together will always be true, unless you can make the variable be all the values at exactly the same time, which is impossible.

 

You can correct the logic by using an equal test == and OR'in the values to give you a TRUE when one of them matches, or you can use the not equal != test and AND them together, but it is much cleaner to make an array of the possible values and use in_array() or !in_array() to test if a variable is present or not present in the array.

Link to comment
https://forums.phpfreaks.com/topic/80706-solved-upload-type/#findComment-409348
Share on other sites

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.