2011-11-14 42 views
0

我需要制作一个网站,人们可以上传数据文件,经过一些处理后将使用jpgraph进行绘图。该文件使用名为analfile.sh的bash脚本进行分析。 bash脚本是这样的:fopen动态文件名不起作用

#!/bin/bash 

file=$1 
fecha=`date +%s` 
mv $1 $fecha.dat 
echo $fecha.dat 

因此,它给出了另一个文件,其名称是这样的:1321290921.dat。这是我需要绘制的文件。

这是我当前的PHP代码:

$target_path = "/home/myhome"; 
$target_path = $target_path . basename($_FILES['rdata']['name']); 
$target_file = basename($_FILES['rdata']['name']); 

if(move_uploaded_file($_FILES['rdata']['tmp_name'], $target_path)) { 
    echo "The file ". $target_file. " has been uploaded";  
    chdir('/home/myhome');  
    $filetoplot=shell_exec('./analfile.sh'.' '.$target_file);  
} else{  
    echo "There was an error uploading the file, please <a href=\"index.html\">try again! 
</a>"; 
} 

//$filetoplot="1321290921.dat" 
echo "<br>The file to be opened is ". $filetoplot. "<br>"; 

if ($file_handle = fopen("$filetoplot", 'r')) {  
    while ($line_of_text = fgets($file_handle)) { 
    $parts = explode('.', $line_of_text); 
    echo $line_of_text ; 
    print $parts[0] . $parts[1]. $parts[2]. "<br>"; 
    } 
fclose($file_handle);  
} 

我有权读取并在目标目录写。我发现奇怪的是,如果我取消注释行$ filetoplot =“1321290921.dat”,那么脚本完美。我想我正在做一些愚蠢的事情,因为这是我在php中的第一个代码,但经过几个小时的搜索后,我无法找到解决方案。

任何帮助将不胜感激。

+1

仔细检查您是否未在安全模式下运行PHP。 –

回答

0

我看到的第一件事是,您不要在您的主路径中追加尾部斜杠(/),以便路径将如/home/myhomefoo而不是/home/myhome/foo

您还应该提前移动$target_file,并在$target_path之内重新使用它。没有理由做同样的事情两次。

如果这没有帮助,我们会看看接下来会发生什么。