Jump to content

Recommended Posts

how are you assigning $file...show a little more code
I'm assuiming it's an upload file array
but I can't be too sure

and if that is the case
remember you have to include the name of the file upload input box from you HTML

E.G
if you're box looks like this
[code]<input type="file" name="pictures[]" />[/code]

you're print statement must be
[code]print $_FILES['pictures']['type'];[/code]
Link to comment
https://forums.phpfreaks.com/topic/20693-filetype/#findComment-91514
Share on other sites

I'm reading files from a directory. Here is the code. Thanks again.


// open the current directory by opendir
$handle=opendir(".");

while (($file = readdir($handle))!==false) {

    print $file['type'];

if($file['type']=="application/x-php"||$file['type']=="text/html"){
                //doesn't allow .php or .html files to be seen
        }
else{
print "<a href='$file'>Click to download </a>";
print $file.'<br>';
}
}
Link to comment
https://forums.phpfreaks.com/topic/20693-filetype/#findComment-91530
Share on other sites

the reason it doesn't work is because readdir() doesn't return an array
it return a string with JUST the filename in it

you'll have to use the mime_content_type() function to check the filetype

as simple change to your script
[code]
while (($file = readdir($handle))!==false) {

  if(mime_content_type ($file)=="application/x-php"| | mime_content_type ($file)=="text/html"){
               //doesn't allow .php or .html files to be seen
       }
  else{
     print "<a href='$file'>Click to download [/url]";
     print $file.'
';
  }
}

[/code]
Link to comment
https://forums.phpfreaks.com/topic/20693-filetype/#findComment-91544
Share on other sites

I don't know what you did either
readdir() when used right.....will give you the filename...and that's it

$file['type'] is kinda....undefined

when you say it's not printing anything........are you testing this script on a php file/html file
because from you included script....it's not doing anything...explaining the blank print
Link to comment
https://forums.phpfreaks.com/topic/20693-filetype/#findComment-91559
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.