2012-12-16 153 views
-2

我有这段代码在本地顺利运行。该程序仅查找文件并在其上写入数据。当我尝试在服务器上运行同一程序,只是什么也不做......php程序在本地工作,但不在服务器上

这是完整的代码:

<?php 

$myFile = "Current_User.txt"; 
//$produto = "sapato1"; 
//$produto = $produto.";"; 
$i = 0; 
$produto = $_POST["produtoID"]; 
$produto = $produto.";"; 
//$produto = $_POST["produtoID"]; 

    $fh = fopen($myFile, 'r'); 
    $line_of_text = fgets($fh); 
    $str = $line_of_text; 
    $str = str_replace("\n", "", $str); 
    $str = $str."_Cesto.txt"; 
    fclose($fh); 

     $fh2 = fopen($str, "r")or die("can't open file"); 
       while (($line_of_text = fgets($fh2))) { 
         $i++; 
         $line_of_text = str_replace("\n", "", $line_of_text); 
         $line_of_text = str_replace("\r", "", $line_of_text); 
         if($produto == $line_of_text){ 
          break; 
          } 
       } 
      fclose($fh2); 


      $dados = file($str); 
      if($i == 1){ 
       unset($dados[$i - 1]); 
      } 
      else{ 
       unset($dados[$i - 2]); 
      } 
      file_put_contents($str,$dados);   


    ?> 
+1

是否在文件服务器上存在吗? –

+2

什么意思是“什么都不做”? file_put_contents()返回什么代码?也许你只是没有权限在你想存储文件的服务器上? – ualinker

+0

你应该检查$ dados = file($ str)的返回值什么是$ str的可能值,它将是一个本地路径还是它也可以是一个url?如果它可以是一个URL,你必须在PHP配置中设置allow_url_fopen。 –

回答

0

你忘了上传Current_User.txt

+0

这是基于? – Lix

+3

@Lix 古玛雅预言;) –

+0

@Lix:Legit的答案... 如果它在本地服务器上工作没有错误,然后就停止工作,他一定已经忘记了那个文件。除非他想提供关于“什么都不做”的意思的更多信息。 – Oberst

0

你检查Current_User.txt文件的写入权限? 你在服务器上使用什么文件系统?

如果您有权访问:在服务器上检查您的PHP error_log以获得更有价值的答案或更改error_reportings。

2
<?php 

$url = "http://sea-summit.com/T_webservice/get_appointments_by_id.php"; 


$data = array('user_id'=> 1); 


$options = array(
    'http' => array(
    'method' => 'POST', 
    'content' => json_encode($data), 
    'header'=> "Content-Type: application/json\r\n" . "Accept: application/json\r\n")); 

$context = stream_context_create($options); 
$result = file_get_contents($url, false, $context); 
$response = json_decode($result); 



var_dump($response); 

?> 

这段代码是面临着同样的问题,这样的权限可能是原因 或改变方法得到它会工作

相关问题