【发布时间】:2014-04-01 09:39:54
【问题描述】:
我需要在 Blender 中打开用户上传的文件(用于数据检索和处理)。
到目前为止,创建 $cmd 并使用 exec() 运行它;已用于测试,但无法打开用户上传的文件,因为正在运行的文件始终是预定义的 (C:\xampp\htdocs\test.new\test.stl)。
$cmd = '"C:\Users\DJ LX\Documents\blender.old\blender.exe" C:\xampp\htdocs\test.new\test.stl"';
if ((($_FILES["file"]["type"] == "application/netfabb")
|| ($_FILES["file"]["type"] == "application/sla")
|| ($_FILES["file"]["type"] == "fileapplication/sla")
|| ($_FILES["file"]["type"] == "fileapplication/vnd.ms-pki.stl")))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $file . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
exec($cmd);
我尝试只使用 $_FILES 信息,但不起作用。
$cmd = "C:\Users\DJ LX\Documents\blender.old\blender.exe" $_FILES["file"]["type"];
和
$cmd = "C:\xampp\htdocs\test.new\upload" . $_FILES["file"]["type"];
我也尝试过使用分配为 $openfile 的 fopen,然后使用 exec($openfile),但出现错误,说明 exec() 中的第一个参数需要是字符串。
$openfile = fopen($_FILES["file"]["type"], "r");
if ((($_FILES["file"]["type"] == "application/netfabb")
|| ($_FILES["file"]["type"] == "application/sla")
|| ($_FILES["file"]["type"] == "fileapplication/sla")
|| ($_FILES["file"]["type"] == "fileapplication/vnd.ms-pki.stl")))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_FILES["file"]["error"] . "<br>";
}
else
{
echo "Upload: " . $file . "<br>";
echo "Type: " . $_FILES["file"]["type"] . "<br>";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " kB<br>";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
exec($opefile);
无论如何,我真的很困惑如何从上传的文件中获取文件名并使用它来打开文件。任何帮助将不胜感激。
【问题讨论】:
标签: php file dynamic exec fopen