我试图执行此代码但我的代码因为某些原因无法插入表中而死亡。给出的错误是“存储到表中时出错”我查看了我的代码但是看不到我的PDO插入查询或php错误日志有什么问题。
try {
$result = $s3->putObject([
'Bucket' => $config['s3']['bucket'],
'Key' => "uploads/{$name_of_uploaded_file}",
'Body' => fopen($path_of_uploaded_file, 'rb'),
'ACL' => 'public-read'
]);
if (is_uploaded_file($_FILES['uploaded_file']['size'])){
//send items to pending database
//inserts in pending db
$sql = "INSERT INTO pending (id,photo,title,description,name,pLike,pDislike) VALUES ('', :photo, :title, :description, :name, :pLike, :pDislike)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':title', $title);
$stmt->bindParam(':photo', $result);
$stmt->bindParam(':description', $story);
$stmt->bindParam(':name', $first_name);
$stmt->bindValue(':pLike', 0, PDO::PARAM_INT);
$stmt->bindValue(':pDislike', 0, PDO::PARAM_INT);
$stmt->execute();
}else {
die("there was an error in storing to table");
}
//remove the file
unlink($path_of_uploaded_file);
} catch(S3Exception $e){
die("there was an error");
}
答案 0 :(得分:3)
它已在manual中说明了
如果通过HTTP POST上传 filename 命名的文件,则返回TRUE。
为了正常工作,函数is_uploaded_file()需要一个像
这样的参数
$_FILES['userfile']['tmp_name']
,客户端计算机上
$_FILES['userfile']['name']
上传文件的名称不起作用。
现在,您指的是size
索引:
is_uploaded_file($_FILES['uploaded_file']['size']
// ^
应该是:
if (is_uploaded_file($_FILES['uploaded_file']['tmp_name'])){
答案 1 :(得分:1)
try{
$sql = "INSERT INTO pending (id,photo,title,description,name,pLike,pDislike) VALUES ('', :photo, :title, :description, :name, :pLike, :pDislike)";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':title', $title);
$stmt->bindParam(':photo', $result);
$stmt->bindParam(':description', $story);
$stmt->bindParam(':name', $first_name);
$stmt->bindValue(':pLike', 0, PDO::PARAM_INT);
$stmt->bindValue(':pDislike', 0, PDO::PARAM_INT);
$stmt->execute();
}
catch(PDOException $e){
echo 'error in query: '.$e->getMessage();
}
在if语句的第一部分将回显查询中的错误(如果有的话)