私のフォームには、ファイルをアップロードするための 3 つの入力フィールドがあります。
<input type=file name="cover_image">
<input type=file name="image1">
<input type=file name="image2">
cover_image
が空かどうかを確認するにはどうすればよいですか - アップロードするファイルがありませんか?
私のフォームには、ファイルをアップロードするための 3 つの入力フィールドがあります。
<input type=file name="cover_image">
<input type=file name="image1">
<input type=file name="image2">
cover_image
が空かどうかを確認するにはどうすればよいですか - アップロードするファイルがありませんか?
次のようsize
に、配列のフィールドを使用して確認できます。$_FILES
if ($_FILES['cover_image']['size'] == 0 && $_FILES['cover_image']['error'] == 0)
{
// cover_image is empty (and not an error)
}
(何か問題が発生error
した可能性があるため、ここでもチェックします。オーバーライドできるため、このチェックには使用しません)0
name
方法 1
if($_FILES['cover_image']['name'] == "") {
// No file was selected for upload, your (re)action goes here
}
方法 2
if($_FILES['cover_image']['size'] == 0) {
// No file was selected for upload, your (re)action goes here
}
次のようにして、値があるかどうか、および画像が有効かどうかを確認できます。
if(empty($_FILES['cover_image']['tmp_name']) || !is_uploaded_file($_FILES['cover_image']['tmp_name']))
{
// Handle no image here...
}
if (empty($_FILES['cover_image']['name']))
フォームが投稿された後、以下を確認してください
$_FILES["cover_image"]["size"]==0
if( ($_POST) && (!empty($_POST['cover_image'])) ) //verifies if post exists and cover_image is not empty
{
//execute whatever code you want
}
これはうまくいきます
if ($_FILES['cover_image']['size'] == 0 && $_FILES['cover_image']['error'] == 0)
// ファイルが選択されているかどうかをチェックし、エラーではない
{
// ファイルが選択されておらず、エラーではありません
}