如何访问 php.ini 并将 file_upload 指令设置为 "on"

how to access php.ini and set file_upload directive to "on"

我正在做我的学校项目,我们使用 Winscp 作为服务器。 所以我是 php 的新手,尝试处理图像上传,我读过很多文章说我需要编辑我的 php.ini 文件并将 file_uploads 指令设置为 "on"。但我只是不知道我的 php.ini 文件在哪里。

这是我的 link 我的 phpinfo.php:http://cgi.sice.indiana.edu/~baehy/phpinfo.php 所以它说我的 php.ini 在 /etc/php.ini 并且我在我的电脑上找不到它(我知道这听起来可能很傻)

感谢每条评论!提前谢谢大家!

这是我的代码

<?php 
  session_start();
include('database.php');
ini_set('max_exection_time', 60);
if(!isset($_SESSION['userid'])){
header('location: http://cgi.sice.indiana.edu/~baehy/team72index.php');
} else {
echo "Welcome " . $_SESSION['userid'] . "<br>";
if(isset($_POST['submit'])){
$title = $_POST['title'];
$category = $_POST['category'];
$description = $_POST['description'];
//get file from the form and get following information
$file = $_FILES['coverimage'];
$fileName = $_FILES['coverimage']['name'];
$fileTmpName = $_FILES['coverimage']['tmp_name'];
$fileSize = $_FILES['coverimage']['size'];
$fileError = $_FILES['coverimage']['error'];
$fileType = $_FILES['coverimage']['type'];

//retrieve file extention using explode()
$fileExt = explode('.', $fileName);
//because some file extentions might be in capital letters
$fileActualExt = strtolower(end($fileExt));

$allowed = array('jpg','jpeg','png');
if(in_array($fileActualExt, $allowed)){
  if($fileError === 0){
    //if the size of the file is lesser than 1M kb = 1000mb
    if($fileSize < 1000000){
      $fileNameNew = uniqid('',true).".".$fileActualExt;
      chmod('uploads/',0777);
      echo "permission granted to uploads directory!" . "<br>";
      $fileDestination = 'uploads/'.$fileNameNew;
      move_uploaded_file($fileTmpName, $fileDestination);
      echo $fileNameNew . "<br>";
      echo "Successfully uploaded your file" . "<br>";
    } else {
      echo "Your file is too big to upload" . "<br>";
    }
  } else {
    echo "There was an error uploading your file" . "<br>";
  }
} else {
  echo "This file extention is not allowed to be uploaded" . "<br>";
}
$sql = "INSERT INTO `recipe` (title, category, description, coverimage, userid)
VALUES ('".$title."', '".$category."', '".$description."', '".$fileName."', '".$_SESSION['userid']."')";

$result = mysqli_query($conn, $sql);
if($result){
  echo "successfully added to database";
} else {
  echo "failed to add to database";
}
$showImage = mysqli_query($conn, "SELECT `coverimage` FROM `recipe`");
}
}

p.s。并且我还需要放置文件夹的绝对路径('uploads')才能在代码中使用它吗?谢谢!

使用WinSCP,连接到远程服务器。转到远程服务器的根目录,然后转到 /etc/php.ini.

它不会在您的计算机上,它在远程服务器上。服务器是 Apache 上的 运行。您正在使用 Winscp 作为 FTP 软件来访问远程服务器的文件。

了解如何使用 WinSCP - https://www.siteground.com/tutorials/ssh/winscp/

Php.ini 是位于远程 Web 服务器的系统文件,它包含 PHP 的全局配置。只有特权用户才能编辑 php.ini。

您可以使用函数 ini_set 更改脚本的本地配置,例如:

ini_set('max_exection_time', 60);

根据您发送的 phpinfo(),您已经将 file_uploads 设置为开启。所以你不需要编辑任何东西。只需打开您发送的 link,按 CTRL+F 并搜索 file_uploads


顺便说一句,WinSCP 只是用于使用 FTP/SFTP 或类似协议将文件传输到远程 Web 服务器的应用程序。实际上,您的 Web 服务器是 RHEL Apache 2.4.6 上的 运行。请查看您的 phpinfo 中的 SERVER_SOFTWARE 部分。