我试图执行这段代码,但我的代码死了,因为它由于某种原因无法插入到表中。给出的错误是“存储到表时出错”我查看了我的代码但看不到我的 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");
}
最佳答案
它已经在 manual 中说了:
Returns TRUE if the file named by filename was uploaded via HTTP POST.
For proper working, the function is_uploaded_file() needs an argument like
$_FILES['userfile']['tmp_name']
,the name of the uploaded file on the client's machine
$_FILES['userfile']['name']
does not work.
现在,您正指向 size
索引:
is_uploaded_file($_FILES['uploaded_file']['size']
// ^
应该是:
if (is_uploaded_file($_FILES['uploaded_file']['tmp_name'])){
关于php - PDO 查询未插入且无错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30095121/