저는 양식에서 사진을 업로드하고, 서버에 파일을 생성하고, 정보를 데이터베이스에 추가하는 기능을 썼습니다.하지만 필자는 원하는대로 정확하게 작업하려고 악몽을 꾸고 있습니다.사진 업로드 문제
편집
현재, 그것은 파일 형식이 잘못되면 올바른 오류 메시지를 표시하고 3메가바이트 이상하지만 난 업로드하려고 할 때 17메가바이트은 취소하고 나를 로그 파일 .BMP. 의도 한 기능을 처리 한 후 내 process.php 파일을 다시 시작하는 것으로 보입니다.
나는 당황 스럽습니다. 그래서 어떤 도움을 주시면 감사하겠습니다. 감사합니다
<form action="process.php" method="POST" enctype="multipart/form-data" name="formUpload">
<label>Picture:</label>
<input type="file" name="photo" id="photobrowser" tabindex="4">
<span class="error"><?php echo $form->error("photo"); ?></span><br />
<input type="hidden" name="sessionid" value="<?php echo $sessionid; ?>" />
<input type="hidden" name="subphoto" value="1" />
<input type="image" src="styling/images/button-add-photo.png" id="subBtn" tabindex="6" />
</form>
process.php
class Process {
function Process(){ /* Class constructor */
global $session;
if(isset($_POST['subphoto'])){ /* User submitted an advert photo */
$this->procAddPhoto();
} else if($session->logged_in){ /* No form was submitted therefor logout */
$this->procLogout();
} else { /* User trying to view this file */
header("Location: /");
}
}
function procAddPhoto(){
global $session, $form;
$retval = $session->addPhoto($_FILES['photo']['size'], $_FILES['photo']['type'], $_FILES['photo']['tmp_name'], $_POST['sessionid']);
if($retval == 0){ /* Successful */
// do stuff
} else if($retval == 1){ /* Errors found */
// do stuff
} else if($retval == 2){ /* Adding failed */
// do stuff
}
} // close function procAddPhoto()
};
$process = new Process; /* Initialize process */
?>
session.php
function addPhoto($subphotoSize,$subphotoType,$subphotoTmpname,$subsessionid){
global $database, $form;
$maxFileSize = 3000000; // bytes (3 MB)
/* Image error checking */
$field = "photo";
if($subphotoSize == 0){
$form->setError($field, "* No file selected");
} else {
list($width, $height, $type, $attr) = getimagesize($subphotoTmpname);
if($width > 4000){
$form->setError($field, "* Max photo width is 4000 pixels.");
} else if($subphotoSize > $maxFileSize) {
$form->setError($field, "* Photo is above the maximum of 3 MB");
} else if(($subphotoType != "image/jpeg") && ($subphotoType != "image/pjpeg") && ($subphotoType != "image/png")){
$form->setError($field, "* $subphotoType is wrong file type");
}
}
/* Errors exist, have user correct them */
if($form->num_errors > 0){
return 1; //Errors with form
} else { // Else use variables
/* Get random string for new filename name */
$randNum = $this->generateRandStr(10);
$filerootpath = PHOTOS_DIR.$subsessionid."/";
$thumbrootpath = PHOTOS_DIR.$subsessionid."/thumbs/";
if($subphotoType == "image/png"){
$filename = $randNum.".png";
} else if ($subphotoType == "image/jpeg" || $subphotoType == "image/pjpeg"){
$filename = $randNum.".jpg";
}
$fullURL = $filerootpath.$filename;
$thumbURL = $thumbrootpath.$filename;
/* Make sure file is RGB colors */
$getimagesize = getimagesize($subphotoTmpname);
if (isset($getimagesize['channels']) && $getimagesize['channels'] == 4 && $getimagesize[2] == IMAGETYPE_JPEG) {
$im = @imagecreatefromjpeg($subphotoTmpname);
if ($im) {
imagejpeg($im, $image, 75);
imagedestroy($im);
}
}
/* Upload files to correct folders */
move_uploaded_file($subphotoTmpname, "$fullURL");
/* Use session ID for the advert ID because it hasnt been made yet */
$userSession = $this->userinfo['userid'];
$ownerID = $this->userinfo['id'];
if(!$database->addNewPhoto($ownerID,$fullURL,$userSession,$is_main_photo, $subsessionid, $thumbURL)){
return 2; // Failed to add to database
}
}
return 0; // Success
}
"파일 크기가 몇 MB 인 경우를 제외하고는 사용자가 완전히 로그 아웃됩니다."사용자가 그 것을 좋아할 것입니다 ... – Brad
감사합니다. – user29660