开发者

Uploading a .jar with php problem

I am building a php application. I can easily upload an image or any other type of data, but not a .jar. Below my code:

Upload.php

<form action="getfile.php" method="post" name="uploadForm" id="uploadForm" enctype="multipart/form-data"  ><br>
    <?php echo gettext("Image "); ?> 
        <input name="imagen" value="" type="file" id="imagen" />

    <?php echo gettext("Jar "); ?> 
        <input name="jarFile" value="" type="fil开发者_JAVA技巧e" id="jarFile" />
</form>

getfile.php

$fileName = $_FILES['jar']['name'];
$fileType = $_FILES['jar']['type'];
//Check the extension
if (!strpos($fileType, "jar") ) {
    echo gettext("The simulation must be jar extension. Try again.");
}else{

    if (move_uploaded_file($_FILES['jar']['tmp_name'], $path)){
       echo gettext("Simulation stored succesfully.");
    }else{
       echo gettext("Something happened. Try again. ");
    }
}

For images I am following the same aproach, but when I try to upload a jar file, I am always getting the error

The simulation must be jar extension. Try again

and $fileType is empty. Is there some restriction at this point? Am I missing something??

Thanks in advance


The type property is unreliable (and populated by the browser). Your best bet is to retrieve the MIME file type:

$fhandle = finfo_open(FILEINFO_MIME);
$mime_type = finfo_file($fhandle, $_FILES['jar']['tmp_name']);

The $mime_type should be application/java-archive.

PHP >= 5.3.0

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜