【问题标题】:PHP / SQL: cannot save image at server but successful save image link at SQL databasePHP / SQL:无法在服务器上保存图像,但在 SQL 数据库中成功保存图像链接
【发布时间】:2020-06-09 20:06:27
【问题描述】:

目前我创建了一个 android 系统,可以从相机拍摄照片并将其保存到 Microsoft SQL 数据库。当我使用 localhost (XAMPP) 时,图像成功存储在“images”文件夹中,并创建了链接并保存到 MySQL 数据库。

但是当我想更改为 Microsoft SQL Server 2016 时,捕获的图像没有保存在“images”文件夹中,而是创建了链接并保存到 Microsoft SQL 数据库。发现的错误在PHP端,下面是错误:

1) PHP 警告:file_put_contents(images/before_3.png):无法打开流:第 22 行 C:\inetpub\wwwroot\tgotworker_testing\android2\task_update_before.php 中的权限被拒绝

以下是php代码:

<?php
require_once "../config/configPDO.php";

$defID = 0;
$photo_before = $_POST['photo_before'];
$report_id = $_GET["report_id"] ?? "";

$stmt = $conn->query("SELECT * FROM ot_report ORDER BY report_id ASC");
while($row = $stmt->fetch(PDO::FETCH_ASSOC)){
$defID = $row['report_id'];
}

$defID = "before_" . $defID;
$imgPath = "images/$defID.png";
$ServerURL = "http://172.20.0.45/tgotworker_testing/android2/$imgPath";

$sql = "UPDATE ot_report SET photo_before ='$ServerURL', time_photo_before = GETDATE(), ot_start = '16:00:00' WHERE report_id = '$report_id'";
$query = $conn->prepare($sql);
$query->execute();

if($query){
    file_put_contents($imgPath,base64_decode($photo_before)); //line 22
    echo "Data Save!";
}else{
    echo "Error!! Not Saved";
}

?>  

谁能帮我解决这个问题?谢谢。

【问题讨论】:

    标签: php android mysql sql sql-server


    【解决方案1】:

    作为警告

    1) PHP Warning: file_put_contents(images/before_3.png): failed to open stream: Permission denied in C:\inetpub\wwwroot\tgotworker_testing\android2\task_update_before.php on line 22
    

    明确指出,运行 PHP 脚本的用户无权 访问该images/before_3.png 文件。我对 Windows 上的 PHP 不是很熟悉,但我建议以管理员权限运行该脚本。

    【讨论】:

    • @我能知道如何使用管理员运行脚本吗?
    • 首先,您是如何正常运行脚本的?从中我们可以弄清楚如何像管理员一样做。
    猜你喜欢
    • 2015-08-13
    • 1970-01-01
    • 2020-06-17
    • 1970-01-01
    • 1970-01-01
    • 2016-09-28
    • 1970-01-01
    • 1970-01-01
    • 2013-07-01
    相关资源
    最近更新 更多