【发布时间】:2016-03-31 15:56:38
【问题描述】:
编辑
我现在有这个 PHP 代码:
$name = isset($_POST['image_file']) ? $_POST['image_file'] : '';
$date_added = date ("F d Y H:i:s.", filectime(basename($_FILES["image_file"]["tmp_name"])));
$path = "../uploads/".basename($_FILES["image_file"]["name"]);
$patient_id = $_POST['patient_id'];
$remark = $_POST['remark'];
//$date_added = $_POST['date_added'];
$ext = pathinfo($path, PATHINFO_EXTENSION);
...
任何文件(图片除外)的结果都是:January 01 1970 01:00:00.
当我尝试上传图片时,它会将我发送到一个空白页面,该页面没有显示错误并且图片没有上传到文件夹中。
结束编辑
我需要使用此表格将扫描的图像添加到患者文件中:
<form enctype="multipart/form-data" id="myForm" name="myForm" action="add_scan.php" method="post">
<div class="box-body" id="toggleDiv">
<div class="row">
<div class="col-md-6">
<div class="form-group">
<label style="float:left">File Description</label>
<input type="text" class="form-control" id="remark" name="remark"/>
<label style="float:left">Upload File</label>
<input type="file" class="form-control" id="image_file" name="image_file"/>
<input type="hidden" class="form-control" id="patient_id" name="patient_id" value="<?php echo $patient_id ?>"/>
</div><!-- /.form-group -->
<button type="submit" class="btn btn-warning" id="add_scan" name="add_scan">Add File</button>
</form>
通常,我的客户会添加日期,但有时他会忘记拍摄图像的日期。所以我需要访问图像的系统日期。
我尝试了以下方法:
Add_scan.php页面:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
require_once('../include/global.php');
//session_start();
$user = $_SESSION['username'];
$id_logged = $_SESSION['login_id'];
if(isset($_POST['add_scan']))
{
try
{
$name = isset($_POST['image_file']) ? $_POST['image_file'] : '';
$path = "../uploads/".basename($_FILES["image_file"]["name"]);
$date_added = date ("Y-m-d", filectime(basename($_FILES["image_file"]["name"])));
$patient_id = $_POST['patient_id'];
$remark = $_POST['remark'];
//$date_added = $_POST['date_added'];
$ext = pathinfo($path, PATHINFO_EXTENSION);
move_uploaded_file($_FILES["image_file"]["tmp_name"], $path.$name);
$sqlUpd = "INSERT INTO scan_image(id_logged, patient_id, image_file, remark, date_added)
VALUES(:id_logged, :patient_id, :image_file, :remark, :date_added)";
$stmt = $conn->prepare($sqlUpd);
$stmt->bindValue(':id_logged', $id_logged);
$stmt->bindValue(':patient_id', $patient_id);
$stmt->bindValue(':image_file', $path);
$stmt->bindValue(':remark', $remark);
$stmt->bindValue(':date_added', $date_added);
$stmt->execute();
header("Location: patients.php?patient=".$patient_id);
}
catch(PDOException $e)
{
echo $e->getMessage();
}
?>
我在哪里使用这一行:$date_added = date ("Y-m-d", basename($_FILES["image_file"]["name"])); 根据 PHP PDO 文档 in this link 访问日期。
但没有添加任何内容,我只看到我的 add_scan.php 代码的空白页,它没有重定向到 patient.php 页面。
【问题讨论】:
-
有错误吗?你打开error reporting了吗?
-
是的,它已经在代码中了
标签: php file-upload