많은 예제를 보았지만 현재 업로드 스크립트를 어떻게 묶을 수 있는지 잘 모르겠습니다. 누군가 w : h 비율을 유지하면서 ImageMagick 등을 사용하여 업로드 된 이미지의 크기를 고정 폭으로 조정할 수있는 방법을 설명해 주시겠습니까?PHP 이미지 크기 조정 및 내 업로드 스크립트
나는 인터넷 검색을하고 150 개가 넘는 웹 페이지를 보았지만 그 중 아무도 내 상황에 맞는 느낌을주는 사례는 제공하지 않았다. 어떤 도움을 주시면 감사하겠습니다. 여기 내 코드는 다음과 같습니다
// Include Extension finder function.
include_once 'find_extension.php';
// Function Gathers the Input Name, Store Number and Picture Number. The picture number is assigned by the loop that will be cycling through the images to be uploaded. The store Number and the Picure Number will make the file name.
function uploadImage($inputname, $storenum, $picturenum){
// A few parameters, to restrict file types and file size to 20kb.
if ((($_FILES[$inputname]["type"] == "image/gif")
|| ($_FILES[$inputname]["type"] == "image/png")
|| ($_FILES[$inputname]["type"] == "image/jpeg")
|| ($_FILES[$inputname]["type"] == "image/pjpeg"))
&& ($_FILES[$inputname]["size"] < 200000))
{
// If there is an error, echo the error, if not continue.
if ($_FILES[$inputname]["error"] > 0){
echo "Error: " . $_FILES[$inputname]["error"] . "<br />";
}else{
// Echo out File information.
/* echo "Upload: " . $_FILES[$inputname]["name"] . "<br />";
echo "Type: " . $_FILES[$inputname]["type"] . "<br />";
echo "Size: " . ($_FILES[$inputname]["size"]/1024) . " Kb<br />";
echo "Stored in: " . $_FILES[$inputname]["tmp_name"]; */
}
// Get the extension so we can rename using the previous function.
$ext = findexts($_FILES[$inputname]["name"]);
$newpicturename = $storenum . $picturenum . "." . $ext;
// Check to see if the file exists, if it does then tell the user. If not continue.
if (file_exists("userimages/" . $newpicturename)){
echo "<br>" . $newpicturename . " already exists. ";
}else{
// Uploads the file.
move_uploaded_file($_FILES[$inputname]["tmp_name"], "userimages/" . $newpicturename);
$picturefield = "picture" . $picturenum;
$picturepath = "userimages/" . $newpicturename;
//Inserts data into ad DB
mysql_query("UPDATE storead SET $picturefield='$picturepath' WHERE storenum='$storenum'");
// Tells the User.
// echo "Stored in: " . "userimages/" . $newpicturename;
}
}else{
// If the upload does not meet the parameters above, then tell the user and cancel.
echo "Error uploading " . $_FILES[$inputname]["name"] . ". File may be too large or of unnacepted format.";
}
}
당신을 :) 감사
감사합니다. bob, 보안 이미지 업로드에 대한 좋은 자료가 있으십니까? –
당신은이 웹 사이트가 대부분의 기지를 다룰 것이라고 생각합니까? http://www.mysql-apache-php.com/fileupload-security.htm –
Andrew, 나는 이것을하기위한 쉬운 방법을 찾고 있으며 웹 디렉토리 위에 업로드하는 것에 대한 많은 제안을 보았습니다. 그러나 내 스크립트는 여전히 웹 사이트의 방문자에게 이러한 파일을 표시합니다. 확실한 화이트리스트 작성과 결합하여 이것이 안전한 경로라고 생각합니까? 그런 종류의 화이트리스트 작성이 가능합니까? 나는이 일을 끝내기를 원한다. 너무 복잡하다. 고맙습니다!! –