Re: file_finfo not valid resource, has anyone used this?
Posted: Sat Jan 09, 2010 1:17 pm
Also, have you tried just:
Code: Select all
$finfo = finfo_open(FILEINFO_MIME);A community of PHP developers offering assistance, advice, discussion, and friendship.
http://forums.devnetwork.net/
Code: Select all
$finfo = finfo_open(FILEINFO_MIME);It is using the same magic file that finfo uses by default so it should be as accurate. Also, if you really want to use the /usr/local/apache/conf/magic file, then you can pass that to 'file' with the -m option.scarface222 wrote:I tried that I just get then...bloody pain
Warning: finfo_open() [function.finfo-open]: Failed to load magic database at '/usr/share/misc/magic'. in /home/collab13/public_html/testing123.php on line 3
maybe I should just use your way. I guess that is a unix file command that you showed me?
Is it recommendable for file uploads for checking mp3s and images? (i use getimagesize for images but need something good for mp3s) I asked is it safe because I basically want the most accurate way possible to prevent people from uploading malicious files. I read your article and explained a lot how it worked but not so much whether it is accurate enough to use for uploads.
You need to do it like this (file will add the .mime to the end of the magic), but -bi should be sufficient:scarface222 wrote:thanks man, the magic file must not work then, I used -mi and got no response, however bi does. I will try to figure this stupid thing out. What bugs me is that under php info it states the directory to the magic file mime_magic.magicfile /usr/local/apache/conf/magic, however there must be something wrong. Thanks for your help everyone I will try to figure out this thing.
Code: Select all
file -bim /usr/local/apache/conf/magic filenameTry a space after /magicscarface222 wrote:Thanks for the reply man I did it like this and still no response, so I am contacting my system admin to get this sorted, the file is stated to exist, but it seems like there might be a problem with it if neither methods work
$type = exec('file -bim /usr/local/apache/conf/magic' . escapeshellarg($_FILES['file']['tmp_name']));
Code: Select all
<?php
header('Expires: Tue, 08 Oct 1991 00:00:00 GMT');
header('Cache-Control: no-cache, must-revalidate');
if(isset($_GET['uid'])){
$status = apc_fetch('upload_' . $_GET['uid']);
echo round($status['current']/$status['total']*100);
}
?>Code: Select all
<?php
if($_SERVER['REQUEST_METHOD']=='POST') {
$status = apc_fetch('upload_'.$_POST['APC_UPLOAD_PROGRESS']);
$status['done']=1;
echo json_encode($status);
exit;
} else if(isset($_GET['progress_key'])) {
$status = apc_fetch('upload_'.$_GET['progress_key']);
echo json_encode($status);
exit;
}
?>Code: Select all
<html>
<head>
<script type="text/javascript" src="yui/yahoo.js"></script>
<script type="text/javascript" src="yui/event.js"></script>
<script type="text/javascript" src="yui/dom.js"></script>
<script type="text/javascript" src="yui/animation.js"></script>
<script type="text/javascript" src="yui/dragdrop.js"></script>
<script type="text/javascript" src="yui/connection.js"></script>
<script type="text/javascript" src="yui/container.js"></script>
<link rel="stylesheet" type="text/css" href="yui/container.css" />
<script type="text/javascript">
var fN = function callBack(o) {
var resp = eval('(' + o.responseText + ')');
var rate = parseInt(resp['rate']/1024);
if(resp['cancel_upload']) {
txt="Cancelled after "+resp['current']+" bytes!";
} else {
txt=resp['total']+" bytes uploaded!";
}
txt += "<br>Upload rate was "+rate+" kbps.";
document.getElementById('pbar').style.width = '100%';
document.getElementById('ppct').innerHTML = "100%";
document.getElementById('ptxt').innerHTML = txt;
setTimeout("progress_win.hide(); window.location.reload(true);",2000);
}
var callback = { upload:fN }
var fP = function callBack(o) {
var resp = eval('(' + o.responseText + ')');
if(!resp['done']) {
if(resp['total']) {
var pct = parseInt(100*(resp['current']/resp['total']));
document.getElementById('pbar').style.width = ''+pct+'%';
document.getElementById('ppct').innerHTML = " "+pct+"%";
document.getElementById('ptxt').innerHTML = resp['current']+" of "+resp['total']+" bytes";
}
setTimeout("update_progress()",500);
} else if(resp['cancel_upload']) {
txt="Cancelled after "+resp['current']+" bytes!";
document.getElementById('ptxt').innerHTML = txt;
setTimeout("progress_win.hide(); window.location.reload(true);",2000);
}
}
var progress_callback = { success:fP }
function update_progress() {
progress_key = document.getElementById('progress_key').value;
YAHOO.util.Connect.asyncRequest('GET','form.php?progress_key='+progress_key, progress_callback);
}
var progress_win;
function postForm(target,formName) {
YAHOO.util.Connect.setForm(formName,true);
YAHOO.util.Connect.asyncRequest('POST',target,callback);
/* Is there some event that triggers on an aborted file upload? */
/* YAHOO.util.Event.addListener(window, "abort", function () { alert('abort') } ); */
progress_win = new YAHOO.widget.Panel("progress_win", { width:"420px", fixedcenter:false, underlay:"shadow", close:false, draggable:true, modal:true, effect:{effect:YAHOO.widget.ContainerEffect.FADE, duration:0.3} } );
progress_win.setHeader("Uploading "+document.getElementById('test_file').value+" ...");
progress_win.setBody('<div style="height: 1em; width: 400px; border:1px solid #000;"> <div id="pbar" style="background: #99e; height: 98%; width:0%; float:left;"> </div> <div id="ppct" style="height: 90%; position: absolute; margin: 1 0 0 185;">0%</div></div><div id="ptxt" style="margin: 3 0 0 5">0 of 0 bytes</div>');
progress_win.render(document.body);
update_progress();
}
</script>
</head>
<body>
<form enctype="multipart/form-data" id="upload_form" action="upload.php" onsubmit="postForm('form.php','upload_form'); return false;" method="POST">
<input type="hidden" name="APC_UPLOAD_PROGRESS" id="progress_key" value="<?php echo uniqid()?>"/>
<input type="file" id="test_file" name="test_file"/><br/>
<input type="submit" value="Upload!"/>
</form>
<div id="progress_win">
<div class="hd" style="color: #222; background: #bbb"></div>
<div class="bd"></div>
<div class="ft"></div>
</div>
</body>
</html>Code: Select all
<?php
if($_FILES['test_file']['error'] == UPLOAD_ERR_OK){
$path = 'testingimage/';
$path .= basename($_FILES['test_file']['name']);
if(move_uploaded_file($_FILES['test_file']['tmp_name'], $path)){
// upload successful
}
}
?>