PHP一致的问题,没有与代码有关的错误,也没有预期的输出

时间:2014-01-24 09:52:11

标签: php

你可能会注意到本文的上下文,我是一个初学者学习php。我主要注意到我面临一个有趣但令人沮丧的问题。我一直没有错误的代码,但我的预期输出并不总是回显或显示在页面上。这是我需要注意的关于我如何用PHP做事或有新手看到这个奇怪的问题。我经常不得不回溯代码,看看我的错误是什么,但没有错误。提前谢谢!

---------功能(多个)----------

  function change_profile_image($user_id, $file_temp, $file_extn){

  $file_path = '$_SERVER[DOCUMENT_ROOT]/images/profile_images/' . substr(sha1(time()), 0, 10) . '.' . $file_extn;
  move_uploaded_file($file_temp, $file_path);
  mysql_query("UPDATE `users` SET `profile` = '" . mysql_real_escape_string($file_path) . "' WHERE `user_id` = " . (int)$user_id);

  }

---------个人资料php文件-------      

      $file_name = $_FILE['profile']['name'];
      $file_extn = strtolower(end(explode('.', $file_name)));
      $file_temp = $_FILE['profile']['tmp_name'];

      if(in_array($file_extn, $allowed) === true){
         change_profile_image($session_user_id, $file_temp, $file_extn);
         header('Location:' .$current_file);
         exit();
      }else{
          $errors[] = 'Incorrect file type. Allow: ';
          echo implode(', ', $allowed);
      }
    }
  }
  if(empty($user_data['profile']) === false){
     echo '<image src="', $user_data['profile'],'" alt="', $user_data['first_name'], '\'s Profile Image">';
   }
   ?>
    <form action="" method="post" enctype="multipart/form-data">
        <input type="file" name="profile"> <input type="submit">
    </form>

2 个答案:

答案 0 :(得分:1)

尝试启用错误报告。 让php显示所有错误

error_reporting(E_ALL);
ini_set('display_errors', '1');

在php文件的开头使用此代码段。

或者,您可以检查服务器日志以查看是否出现问题。

答案 1 :(得分:0)

我终于发现了我的代码问题。我有一个语法错误,我应该有$ _FILES和NOT $ FILE。我整个时间或一堆“S”都错过了一个“S”。

相关问题