close ad
 
Important WebAssist Announcement
open ad
View Menu

Technical Support Forums

Free, outstanding support from WebAssist and your colleagues

rating

stuck on a file type filter

Thread began 1/10/2010 10:16 am by gruant2000381341 | Last modified 1/10/2010 12:11 pm by gruant2000381341 | 1521 views | 3 replies |

gruant2000381341

stuck on a file type filter

I need some help, I am trying to set up a filter for an image upload. I want to allow jpeg,jpg,gif,bmp,and PNG

So far, I can only get jpeg,jpg, and gif........I can't get PNG or BMP at all. my code is below. I tried reseting the code to == "*.png" but that didn't work either.


<?php

if (($_FILES["file"]["type"] == "image/gif")

|| ($_FILES["file"]["type"] == "image/jpeg")

|| ($_FILES["file"]["type"] == "image/png")

|| ($_FILES["file"]["type"] == "image/bmp")

|| ($_FILES["file"]["type"] == "image/pjpeg"))


{

if ($_FILES["file"]["error"] > 0)

{

echo "Return Code: " . $_FILES["file"]["error"] . "<br />";

}

else

{

echo "Upload: " . $_FILES["file"]["name"] . "<br />";

echo "Type: " . $_FILES["file"]["type"] . "<br />";

echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";


if (file_exists("upload/" . $_FILES["file"]["name"]))

{

echo $_FILES["file"]["name"] . " already exists. ";

}

else

{

move_uploaded_file($_FILES["file"]["tmp_name"],

"upload/" . $_FILES["file"]["name"]);

echo "Stored in: " . "upload/" . $_FILES["file"]["name"];

}

}

}

else

{

echo "Invalid file";

}

?>

Sign in to reply to this post

anonymous

When you say you can't get BMP or PNG, are you saying they won't upload with the current code you have there?

If that is the case, make sure the files you are working with truly are bitmap and png files. I have seen several cases where the extension is not really what the file is. You may need to the check the properties of said files to ensure the MIME they contain is what it is supposed to be.

Best regards,

Brian

Sign in to reply to this post

gruant2000381341

yes, that's what I meant. I can't get them to upload to the folder.
I right clicked>properties on the images and they are what I thought they were.

under general..type of file ..PNG File (.png)
under details..type of file ..PNG file

What could I be missing?

and I don't think it's a filesize issue...they are both under 500kb

I fixed the bmp part, but the png is still happening

Sign in to reply to this post

gruant2000381341

update

well it has to have something to do with that one filter for png. I removed the filters altogether and now png's will upload....but I really want to filter that.
here's what I have now

<?php
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
?>

Sign in to reply to this post

Build websites with a little help from your friends

Your friends over here at WebAssist! These Dreamweaver extensions will assist you in building unlimited, custom websites.

Build websites from already-built web applications

These out-of-the-box solutions provide you proven, tested applications that can be up and running now.  Build a store, a gallery, or a web-based email solution.

Want your website pre-built and hosted?

Close Windowclose

Rate your experience or provide feedback on this page

Account or customer service questions?
Please user our contact form.

Need technical support?
Please visit support to ask a question

Content

rating

Layout

rating

Ease of use

rating

security code refresh image

We do not respond to comments submitted from this page directly, but we do read and analyze any feedback and will use it to help make your experience better in the future.

Close Windowclose

We were unable to retrieve the attached file

Close Windowclose

Attach and remove files

add attachmentAdd attachment
Close Windowclose

Enter the URL you would like to link to in your post

Close Windowclose

This is how you use right click RTF editing

Enable right click RTF editing option allows you to add html markup into your tutorial such as images, bulleted lists, files and more...

-- click to close --

Uploading file...