用matlab连接php

时间:2015-06-19 14:19:17

标签: php matlab

我有一个html文件test.html

<form enctype="multipart/form-data" action="computeSIFT.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>

运行时上面的代码调用computeSIFT.php文件,该文件调用matlab来对输入图像进行处理

//computeSIFT.php
<?php
#function for streaming file to client
function streamFile($location, $filename, $mimeType='application/octet-    stream')
{ if(!file_exists($location))
{ header ("HTTP/1.0 404 Not Found");
return;
}

$size=filesize($location);
$time=date('r',filemtime($location));
#html response header
header('Content-Description: File Transfer');   
header("Content-Type: $mimeType"); 
header('Cache-Control: public, must-revalidate, max-age=0');
header('Pragma: no-cache');  
header('Accept-Ranges: bytes');
header('Content-Length:'.($size));
header("Content-Disposition: inline; filename=$filename");
header("Content-Transfer-Encoding: binary\n");
header("Last-Modified: $time");
header('Connection: close');      

ob_clean();
flush();
readfile($location);

}


#Main script


#<1>set target path for storing photo uploads on the server
$photo_upload_path = "C:/wamp/www/upload/";
$photo_upload_path = $photo_upload_path. basename( $_FILES['uploadedfile']     ['name']); 
#<2>set target path for storing result on the server
$processed_photo_output_path = "c:/wamp/www/output/processed_";
$processed_photo_output_path = $processed_photo_output_path. basename(      $_FILES['uploadedfile']['name']); 
$downloadFileName = 'processed_' . basename( $_FILES['uploadedfile']['name']); 

#<3>modify maximum allowable file size to 10MB and timeout to 300s
ini_set('upload_max_filesize', '10M');  
ini_set('post_max_size', '10M');  
ini_set('max_input_time', 300);  
ini_set('max_execution_time', 300);  

#<4>Get and stored uploaded photos on the server
if(copy($_FILES['uploadedfile']['tmp_name'], $photo_upload_path)) {

#<5> execute matlab image processing algorithm
#example: Compute and display SIFT features using VLFeat and Matlab

    $command = "matlab -nojvm -nodesktop -nodisplay -r  \"computeSIFT('$photo_upload_path','$processed_photo_output_path');exit\"";
exec($command);

 #<6>stream processed photo to the client
 streamFile($processed_photo_output_path,    $downloadFileName,"application/octet-stream");
    }       
else{

    echo "There was an error uploading the file to $photo_upload_path !";
   }

   ?>

。当html代码在浏览器中进行调整时,它允许用户选择文件并在服务器上传。但是当调用php脚本时,它不会调用matlab来进行处理。所以matlab应该采用输入图像并计算图像的SIFT。它需要花费很多时间而且不会显示结果。 有没有办法知道matlab是否被实际调用或没有?我参考了以下教程,但它没有正常工作。如果我出错了,请告诉我。任何帮助将不胜感激。

链接到我推荐的教程 http://web.stanford.edu/class/ee368/Android/Tutorial-3-Server-Client-Communication-for-Android.pdf

尝试运行matlab程序throgh php命令时,output.log文件的内容如下

Warning: Unable to locate a personal folder for $documents\MATLAB
Warning: Userpath must be an absolute path and must exist on disk.
Exception in thread "FileDecorationCache request queue"       java.lang.RuntimeException: java.io.IOException: Could not get shell folder ID list
at sun.awt.shell.Win32ShellFolderManager2$ComInvoker.invoke(Unknown Source)
at sun.awt.shell.Win32ShellFolder2.getFileSystemPath(Unknown Source)
at sun.awt.shell.Win32ShellFolder2.composePathForCsidl(Unknown Source)
at sun.awt.shell.Win32ShellFolder2.<init>(Unknown Source)
at sun.awt.shell.Win32ShellFolderManager2.getDesktop(Unknown Source)
at sun.awt.shell.Win32ShellFolderManager2.createShellFolder(Unknown Source)
at sun.awt.shell.ShellFolder.getShellFolder(Unknown Source)
at com.mathworks.jmi.MLFileIconUtils.getNativeFileIcon(MLFileIconUtils.java:235)
at com.mathworks.jmi.MLFileIconUtils.getFileIcon(MLFileIconUtils.java:102)
at com.mathworks.mlwidgets.explorer.extensions.basic.DefaultFileInfoProvider$1.run(DefaultFileInfoProvider.java:64)
at com.mathworks.mlwidgets.explorer.model.FileDecorationModel$3$1.run(FileDecorationModel.java:344)
at com.mathworks.util.RequestQueue.execute(RequestQueue.java:105)
at com.mathworks.util.RequestQueue.access$000(RequestQueue.java:22)
at com.mathworks.util.RequestQueue$2.run(RequestQueue.java:75)
at java.lang.Thread.run(Unknown Source)
Caused by: java.io.IOException: Could not get shell folder ID list
at sun.awt.shell.Win32ShellFolder2.getFileSystemPath0(Native Method)
at sun.awt.shell.Win32ShellFolder2.access$900(Unknown Source)
at sun.awt.shell.Win32ShellFolder2$8.call(Unknown Source)
at sun.awt.shell.Win32ShellFolder2$8.call(Unknown Source)
at java.util.concurrent.FutureTask$Sync.innerRun(Unknown Source)
at java.util.concurrent.FutureTask.run(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at sun.awt.shell.Win32ShellFolderManager2$ComInvoker$3.run(Unknown Source)
... 1 more
{Undefined function 'computeSIFT' for input arguments of
type 'char'.
} 

0 个答案:

没有答案