file detection script

Started on the old forum in March 2009 · view the original in the archive · old links redirect here

10 replies · 965 views · started 17 years ago · 1 min read

8 participants
rainforest Newbie · 4 posts #1

need the php code..can anyone share?

ori Lead · 512 posts #2

do u mean the file that downloads files for the type file it is so there no errors/ or browser running the file lol

GiLL Senior · 356 posts #3

Do you want something like this ?

<?
if (!isset($_POST['Submit'])) {
     
     
          include('html/upload.phtml');     //form to upload
     
     
          exit;
     
     }
     
$this_file = $_FILES['file']['tmp_name'];     //gets the path to the directory holding the uploaded file

$type = mime_content_type($this_file);     //error here

echo "<html>$type</html>";

exit;

?>

or

Does $this_file really contain a valid file?

Do a ...

if (file_exists($this_file))
 {
 echo "File $this_file exists.";
 }
else
 {
 echo "File $this_file does NOT exist!";
 }  

left wap stuff

something else Fellow · 2,296 posts #4

maybee external size and type ?

///$file = "http://somesite.com/files/music.mp3";////example file
$something = get_headers($file, 1);
$size = $something['Content-Length'];
$type = $something['Content-Type'];
echo "<a href=\"$file\">music.$type</a> $size bytes
";
rainforest Newbie · 4 posts #5

im not sure if u ppl have gt it..im xplaining it..suppose one of our member is gonna upload an mp3 through the uploader..and when the member iz uploading the file i want that file detectn script that will automatically detect the file extnsn and this info will automatically be gone to the database..juz lyk our browser/ip detection or file size codings..now nyone can help?

alesh Lead · 604 posts #6

you could found that in any lava script...

function getextimg($ext)
{
    $ext = strtolower($ext);
    switch ($ext)
    {
	  case "jar":
	  case "jad":
        return "<img src=\"images/games.gif\" alt=\"igre\"/>";
        break;
      case "jpg":
      case "jpeg":
      case "gif":
      case "png":
      case "bmp":
        return "<img src=\"images/image.gif\" alt=\"image\"/>";
        break;
      case "zip":
      case "rar":
        return "<img src=\"images/pack.gif\" alt=\"package\"/>";
        break;
      case "amr":
      case "wav":
      case "mp3":
      case "mid":
        return "<img src=\"images/music.gif\" alt=\"music\"/>";
        break;
      case "mpg":
      case "3gp":
      case "mp4":
        return "<img src=\"images/video.gif\" alt=\"video\"/>";
        break;
      default:
        return "<img src=\"images/other.gif\" alt=\"!\"/>";
        break;
    }
}

eeeeerrr....

rukiya Lead · 569 posts #7

alesh wrote: you could found that in any lava script...

function getextimg($ext)
{
    $ext = strtolower($ext);
    switch ($ext)
    {
	  case "jar":
	  case "jad":
        return "<img src=\"images/games.gif\" alt=\"igre\"/>";
        break;
      case "jpg":
      case "jpeg":
      case "gif":
      case "png":
      case "bmp":
        return "<img src=\"images/image.gif\" alt=\"image\"/>";
        break;
      case "zip":
      case "rar":
        return "<img src=\"images/pack.gif\" alt=\"package\"/>";
        break;
      case "amr":
      case "wav":
      case "mp3":
      case "mid":
        return "<img src=\"images/music.gif\" alt=\"music\"/>";
        break;
      case "mpg":
      case "3gp":
      case "mp4":
        return "<img src=\"images/video.gif\" alt=\"video\"/>";
        break;
      default:
        return "<img src=\"images/other.gif\" alt=\"!\"/>";
        break;
    }
}

thats definately incompelete which cant get file extention from a file

subzero Super moderator Fellow · 3,954 posts #8
function findexts($file) 
{ 
$ufile = strtolower($file) ; 
$exts = split("[/\\.]", $file) ; 
$n = count($exts)-1; 
$exts = $exts[$n]; 
return $exts; 
} 

How to use

echo findexts( You file name goes here );

😀

Visit: Chat4u.mobi - The New Lay Of being a site of your dreams! Visit: WapMasterz Coming Back Soon!


SCRIPTS FOR SALE BY SUBZERO Chat4u Script : coding-talk.com/f28/chat4u-mobi-script-only-150-a-17677/ - > Best Script for your site no other can be hacked by sql or uploaders. FileShare Script : coding-talk.com/f28/file-wap-share-6596/ -> Uploader you will never regret buying yeah it mite be old now but it still seems to own others... _______…

alesh Lead · 604 posts #9

rukiya wrote: thats definately incompelete which cant get file extention from a file

lol you're right

its missing

function getext($strfnm)
{
  $str = trim($strfnm);
  if (strlen($str)<4){
    return $str;
  }
  for($i=strlen($str);$i>0;$i--)
  {
    $ext .= substr($str,$i,1);
    if(strlen($ext)==3)
    {
      $ext = strrev($ext);
      return $ext;
    }
  }
}

eeeeerrr....

Guest #10

rainforest wrote: im not sure if u ppl have gt it..im xplaining it..suppose one of our member is gonna upload an mp3 through the uploader..and when the member iz uploading the file i want that file detectn script that will automatically detect the file extnsn and this info will automatically be gone to the database..juz lyk our browser/ip detection or file size codings..now nyone can help?


As I understand ur problem, I made this one. NOTE: You can use own variable where I write ['myfile'], it depand on what variable you defined for uploading file. Like : <input type="file" name="myfile" />

 $file_name = $_FILES['myfile']['name'];//Return File Name
 $file_type = $_FILES["myfile"]["type"];//Return File Type
 $file_size = ceil($_FILES["myfile"]["size"] / 1024); //Return File Size in KB
 $file_ext = substr($file_name, -3);//Return File extension
 /*Now you can send these info into your database when user upload any file*/
 

Sorry if you could not understand my english lol

tkreturns Developer · 98 posts #11

U want to detect the file ??? I mean detect its size, extension(format) ?

ASK FOR HELP

Sign in to reply.

Similar topics

Keyboard shortcuts

g f
Go to forums
g h
Go to your feed
g m
Go to messages
r
Reply (in a topic)
/
Search
j
Next post
k
Previous post
?
This list
Ctrl/⌘ + Enter
Send what you are writing
Ctrl/⌘ + B / I
Bold / italic while writing
Esc
Close