You are here: Re: [PHP] Is there an alternative for $_FILES['guildimage']['type'] == "image/jpeg" « PHP « IT news, forums, messages
Re: [PHP] Is there an alternative for $_FILES['guildimage']['type'] == "image/jpeg"

Posted by Stephen Leaf on 11/23/05 05:33

I use the fileinfo pecl. http://pecl.php.net/Fileinfo

how to get a mime type:
$info = new finfo( FILEINFO_MIME );
$mime = $info->file($filename);

then my extention grabber:
function getExtention() {
switch ( $this->mimeType ) {
case "image/jpeg": return 'jpg'; break;
case "image/png": return 'png'; break;
case "image/gif": return 'gif'; break;
default: throw new ImageTypeNotSupportedException();
}
}

This is all done in a Image Object.

On Tuesday 22 November 2005 08:15 pm, twistednetadmin wrote:
> I use this line in a script for uploading pictures to a website:
>
> $_FILES['guildimage']['type'] == "image/jpeg"
>
> This works fine when using Mozilla, but it doesn't work with IE.
> How should I do it to get it working with both/all browsers?
>
>
>
> if (isset($_POST['submit'])) //If you
> press submit
> {
> $sysfolder="/guildimages/";
> $filename="".$_FILES['guildimage']['name']."";
>
> if (file_exists($sysfolder . $filename)) //And the
> file exists or there is no file chosen
> {
> echo "Filename exists or no file selected. Please rename the file or
> select a file";
>
> }
> elseif ($_FILES['guildimage']['type'] == "image/jpeg") //If
> the filetype is correct (this is where the change should be I think)
> {
>
> copy ($_FILES['guildimage']['tmp_name'],
> "/guildimages/".$_FILES['guildimage']['name']) //Copy the file
> to folder ("/guildimages")
> or die("Could not copy file"); //Or
> die
>
> echo "Result:<br>\n";
> echo "Filename: ".$_FILES['guildimage']['name']."<br>\n";
> echo "Filesize: ".$_FILES['guildimage']['size']." byte<br>\n";
> echo "Filtype: ".$_FILES['guildimage']['type']."<br>\n";
> echo "Congrats! It worked!\n";
> }
> else
> {
>
> echo "Result:<br>\n";
> echo "Now that didn't seem to work... <br>\n
> Have you checked the size and filetype? <br>\n
> File that failed--> (".$_FILES['guildimage']['name'].")<br>";
>
> }
> }
>
> Does anyone know the answer to this?

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация