jquery를 사용하여 이미지 업로드 포럼의 유효성을 검사하고 게시하는 방법을 알고 싶습니다. 제목과 이미지의 두 가지 입력 만 있습니다. 이 필드 중 하나라도 비어 있거나 업로드 된 파일의 형식이 잘못된 경우 오류를 제공해야합니다. 여기에 당신이 jQuery를 사용하여 파일을 확인할 수 없습니다 코드 I (이 순간에 jQuery를 사용하지 않습니다.)이jQuery를 사용하여 유효성을 검사하고 게시하십시오.
Image.php
<?php
$uploadDir = 'images/'; //Image Upload Folder
if(isset($_POST['Submit']))
{
$title = mysql_real_escape_string($_POST['title']);
$fileName = $_FILES['Photo']['name'];
$tmpName = $_FILES['Photo']['tmp_name'];
$fileSize = $_FILES['Photo']['size'];
$fileType = $_FILES['Photo']['type'];
$filePath = $uploadDir . $fileName;
$result = move_uploaded_file($tmpName, $filePath);
if (!$result) {
echo "Error uploading file";
exit;
}
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}
$query = "INSERT INTO images(title,image) VALUES ('".$title."','".$filePath."')";
mysql_query($query) or die (mysql_error());
}
?>
<form name="Image" enctype="multipart/form-data" action="image.php" method="POST">
<input type="text" name="title" id="title" value=""><br/><br/>
<input type="file" name="Photo" size="20" accept="image/gif, image/jpeg, image/x-ms-bmp, image/x-png"><br/>
<INPUT type="submit" class="button" name="Submit" value=" Submit ">
</form>
감사합니다. jpg 및 gif처럼 –
gif 또는 jpg를 확인하도록 코드를 업데이트했습니다. –