gpt4 book ai didi

php - $_FILES 未设置

转载 作者:行者123 更新时间:2023-11-29 03:52:10 24 4
gpt4 key购买 nike

<分区>

我正在尝试创建一个脚本来上传 .mp3 文件,并将文件名插入数据库。每当我尝试提交表单时,我都会收到错误 The FILES global variable was not set,这是我指定的错误,告诉我 $_FILES 不是设置。

if(empty($_POST['postTitle'])){
$error[] = "Please enter a title.";
}
if(empty($_POST['image'])) {
$error[] = "Please select a file.";
}
if(empty($_POST['postAudio'])) {
$error[] = "Please enter some text";
}

$allowedExts = array("jpg", "jpeg", "gif", "png", "mp3", "mp4", "wma"); // Universal between the image and audio

if(isset($_FILES['image'])){
$imageName = $_FILES['image']['name'];
$extension = substr($imageName, strrpos($imageName, '.') + 1);

if(in_array($extension, $allowedExts)) {
if($_FILES['image']['error'] > 0) {
echo "Return Code: " . $_FILES['image']['error'] . "<br />";
} else {
echo "Upload: " . $_FILES['image']['name'] . "<br />";
echo "Type: " . $_FILES['image']['type'] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

if (file_exists("upload/" . $_FILES["file"]["name"])) {
echo $_FILES["file"]["name"] . " already exists. ";
} else {
move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
$error[] = "There was an error trying to get information about one of your uploads.";
}
} else {
$error[] = "The FILES global variable was not set.";
}

if(!isset($error)){
try {

$query = "INSERT INTO blog_podcasts (postTitle,postImage,postAudio,postDate) VALUES (:postTitle, :postImage, :postAudio, :postDate)";
$query_params = array(
':postTitle' => $_POST['postTitle'],
':postImage' => $imageName,
':postAudio' => $_POST['postAudio'],
':postDate' => date('Y-m-d H:i:s')
);
$stmt = $db->prepare($query);
$result = $stmt->execute($query_params);
} catch(PDOException $e) {
echo $e->getMessage();
}
header('Location: index.php?action=added');
exit;
}
}
?>
<?php
//check for any errors
if(isset($error)){
foreach($error as $error){
echo '<p class="error">'.$error.'</p>';
}
}
?>
<form action='' method='post'>

<p><label>Title</label><br />
<input type='text' name='postTitle' value='<?php if(isset($error)){ echo $_POST['postTitle'];}?>'></p>

<p><label for="file"><span>Filename: </span></label>
<input type="file" name="image" id="file" />

<p><label>Audio:<br />
<input type="text" name="postAudio" /></p>



<p><input type='submit' name='submit' value='Submit'></p>
</form>

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com