このフォーム内のデータベースに記事をアップロードするためのフォームがあります。ファイル アップロード フィールドがあります。ファイル アップロードの目的は次のとおりです。
- ファイル拡張子を画像形式に制限する
- ファイルの名前をランダムなものに変更する
- データベースへのエントリの ID に基づいて新しいディレクトリを作成します
- アップロードされたファイルの拡張子を保持する
送信ボタンを押すたびに、許可されている拡張子のリストにないファイルをアップロードしようとしたとフォームが判断しているように見え、このエラーが出力されます (ただし、フィールドはデータベースにアップロードされます)。
wrong files format , allowed only "Array"
正しいファイル形式を入力していることはわかっているので、なぜそうなるのかはよくわかりません。
public function insert ($field) {
if ($stmt = $this->mysqli->prepare("INSERT INTO articles (title, story, storyb, storyc, author, date_created, section, youtubeid) VALUES (?, ?, ?, ?, ?, ?, ?, ?)")) {
/* Set our params */
$title = isset($_POST['title']) ? $this->mysqli->real_escape_string($_POST['title']) : '';
$story = isset($_POST['story']) ? $this->mysqli->real_escape_string($_POST['story']) : '';
$storyb = isset($_POST['storyb']) ? $this->mysqli->real_escape_string($_POST['storyb']) : '';
$storyc = isset($_POST['storyc']) ? $this->mysqli->real_escape_string($_POST['storyc']) : '';
$author = isset($_POST['author']) ? $this->mysqli->real_escape_string($_POST['author']) : '';
$date_created = isset($_POST['date_created']) ? $this->mysqli->real_escape_string($_POST['date_created']) : '';
$section = isset($_POST['section']) ? $this->mysqli->real_escape_string($_POST['section']) : '';
$youtubeid = isset($_POST['youtubeid']) ? $this->mysqli->real_escape_string($_POST['youtubeid']) : '';
/* Bind our params */
$stmt->bind_param('ssssssss', $title, $story, $storyb, $storyc, $author, $date_created, $section, $youtubeid);
/* Execute the prepared Statement */
$stmt->execute();
/* Echo results */
echo "Inserted {$title} into database\n";
/* Close the statement */
$stmt->close();
}
else {
/* Error */
printf("Prepared Statement Error: %s\n", $mysqli->error);
}
// Handling file upload
$extensions = array(".jpg",".jpeg",".gif",".png", ".JPG", ".JPEG", ".PNG", ".GIF");
$extension = strrchr($_FILES['uploadImage']['name'], '.');
$path = "../files/uploads/articles_gallery/" . $this->mysqli->insert_id;
$filename = uniqid(rand(), true);
if (!in_array($extension, $extensions))
{
echo'<center>wrong files format , allowed only <strong>"'.$extensions.'"</strong></center>';
} else {
if (!is_dir($path))
{
die('Error: ' . $mysqli->error());
}
echo "<h3>1 record added</h3>";
mkdir($path, 0777);
move_uploaded_file($_FILES['uploadImage']['tmp_name'], $path, $filename);
} // File Upload End
}
Insert.php
<div id="form">
<form action="insert.php" method="post" name="insert" id="articleform">
<input type="input" name="title" id="title" class="detail" id="title"/>
<textarea name="story" id="story" class="detail" placeholder="Insert article here"></textarea>
<input id="uploadImage" type="file" name="uploadImage" onchange="PreviewImage();" class="" />
<img id="uploadPreview" style="width: 250px; height: 200px;" />
<textarea name="storyb" id="storyb" class="detail" spellcheck="true" placeholder="Insert article here"></textarea>
<textarea name="storyc" id="storyc" class="detail" spellcheck="true" placeholder="Insert article here"></textarea>
<input type="input" name="author" id="author" class="detail"/>
<? $today = date("l j M Y"); // Monday 13 April 2013 ?>
<input type="hidden" name="date_created" id="date_created" class="detail" value="<? echo $today;?>" />
<input type="hidden" name="section" id="section" class="detail" value="game"/>
<input type="input" name="youtubeid" class="detail" id="youtubeid" />
<input type="submit" id="submit" name="submit" value="Submit Article " />
</form>