누군가 나를 기쁘게 할 수 있는지 궁금합니다.파일 크기 제한 설정 메시지
필자는 필자가 PHP를 작성하는 데 상대적으로 새로운 것을 인정해야하므로 나와 함께 참아주십시오.
인터넷에서 읽은 기사와이 사이트의 @Marcio에서 나온 일류 교훈을 통해 사용자가 이미지 파일을 mySQL 데이터베이스에 저장할 수있는 스크립트를 작성했습니다.
이제 업로드 할 수있는 파일의 크기를 제한하여 조금 더 나아갔습니다. 그러나 파일 크기가 크기보다 커서 업로드 할 수없는 이유를 알려주는 경고 메시지를 추가하고 싶습니다. 한계가 설정되었습니다.
아래 코드에서 볼 수 있듯이이 작업을 시도했습니다. 그러나 불행히도 내가 추가 한 행과 관련이있는 예기치 않은 '>'이 있지만 다른 방법으로 코드하는 방법을 모르는 오류 메시지가 나타납니다.
코드
<?php
// This function makes usage of
// $_GET, $_POST, etc... variables
// completly safe in SQL queries
function sql_safe($s)
{
if (get_magic_quotes_gpc())
$s = stripslashes($s);
return mysql_real_escape_string($s);
}
// If user pressed submit in one of the forms
if ($_SERVER['REQUEST_METHOD'] == 'POST')
{
if (!isset($_POST["action"]))
{
// cleaning title field
$title = trim(sql_safe($_POST['title']));
if ($title == '') // if title is not set
$title = '(No title provided';// use (empty title) string
if (isset($_FILES['photo']))
{
@list(, , $imtype,) = getimagesize($_FILES['photo']['tmp_name']);
// Get image type.
// We use @ to omit errors
if ($imtype == 3) // cheking image type
$ext="png"; // to use it later in HTTP headers
elseif ($imtype == 2)
$ext="jpeg";
elseif ($imtype == 1)
$ext="gif";
else
$msg = 'Error: unknown file format';
if($_FILES["fileupload"]["size"]/1024000 >= 10) // 10mb
{
$fileErrMsg = "<br />Your uploaded file size:<strong>[ ". $_FILES["fileupload"]["size"]/1024000 . " MB]</strong> is more than allowed 10MB Size.<br />";
}
if (!isset($msg)) // If there was no error
{
$data = file_get_contents($_FILES['photo']['tmp_name']);
$data = mysql_real_escape_string($data);
// Preparing data to be used in MySQL query
mysql_query("INSERT INTO {$table}
SET ext='$ext', title='$title',
data='$data'");
$msg = 'Success: Image Uploaded';
}
}
아래로 잘라를 개정 난 그냥 누군가가 아마도이 살펴보고 나를 내가 잘못 알려 수 있는지 궁금.
많은 감사와 안부 픽셀
어느 라인에 결함이 사용할 수 있습니다이의 라인을 따라 뭔가가 필요? 그리고 @를 사용하여 디버그 오류를 표시하지 마십시오. – ajreal