2014-07-19 7 views
0

이 튜토리얼을 사용하여 이미지 업 로더를 작성했습니다.이미지 업로드, 파일 확장명을 인식하지 못함

http://www.codeforest.net/upload-crop-and-resize-images-with-php

이것은

https://gist.github.com/philBrown/880506/download#

그러나, 라이브러리를 사용하여 I 양식을 통해에 파일을 통과 어느 문 (이미지를 업로드하시기 바랍니다) 경우, 항상 마지막에 실패 할 때

<?php 
require_once(dirname(__FILE__).'/../config.php'); 
require_once(dirname(__FILE__).'/ImageManipulator.php'); 

if ($_FILES['fileToUpload']['error'] > 0) { 
    echo "Error: " . $_FILES['fileToUpload']['error'] . "<br />"; 
} else { 
    // array of valid extensions 
    $validExtensions = array('.jpg', '.jpeg', '.gif', '.png', '.JPG', '.JPEG', '.PNG', '.GIF', '.bmp'); 
    // get extension of the uploaded file 
    $fileExtension = strrchr($_FILES['fileToUpload']['name'], "."); 
    // check if file Extension is on the list of allowed ones 
    if (in_array($fileExtension, $validExtensions)) { 
     $newNamePrefix = time() . '_'; 
     $manipulator = new ImageManipulator($_FILES['fileToUpload']['tmp_name']); 
     $width = $manipulator->getWidth(); 
     $height = $manipulator->getHeight(); 
     $centreX = round($width/2); 
     $centreY = round($height/2); 
     // our dimensions will be 80by80 
     $x1 = $centreX - 40; // 80 
     $y1 = $centreY - 40; // 80 

     $x2 = $centreX + 40; // 80 
     $y2 = $centreY + 40; // 80 

     // center cropping to 80by80 
     $newImage = $manipulator->crop($x1, $y1, $x2, $y2); 
     // saving file to uploads folder 
     $manipulator->save('/images/avatars/uploaded/' . $newNamePrefix . $_FILES['fileToUpload']['name']); 
     echo 'Done ...'; 
    } else { 
     echo 'You must upload an image...'; 
    } 
} 
?> 
: 아래

코드입니다

그리고 여기에 양식이 있습니다.

<h4>Change Avatar</h4> 
    <form enctype="multipart/form-data" method="post" action="/lib/uploadimage.php"><table class="table table-striped"> 
    <tr><td>Please choose a file:</td><td><input type="file" name="fileToUpload" id="fileToUpload" /> 
    <tr><td colspan="2"><input type="submit" value="Upload"></td></tr> 
    </table></form> 

나는이 작업을 한 번하고 데이터베이스에 URL을 삽입하려고합니다.

나는 아파치 로그가 어떤 오류도주지 않고 폴더에 757 권한을 가지고 있지만 업로드 측면에서는 실패한다고 가정하고 있습니다.

왜 이것이 실패했는지 알 수 있습니까?

편집 : 아파치를 통해 오류가

log:[Sat Jul 19 20:48:51 2014] [error] [client 82.46.57.58] PHP Notice: Undefined index: fileToUpload in /var/SITE/lib/uploadimage.php on line 5, referer: SITE/index.php 

편집이다 : 더 깊이 파고, 권한 문제

SITE:[Sat Jul 19 21:31:58 2014] [error] [client 82.46.57.58] PHP 2. ImageManipulator->save() /SITE/lib/uploadimage.php:30, referer: SITE/index.php 
SITE:[Sat Jul 19 21:31:58 2014] [error] [client 82.46.57.58] PHP 3. mkdir() /SITE/lib/ImageManipulator.php:222, referer: SITE/index.php 
SITE:[Sat Jul 19 21:31:58 2014] [error] [client 82.46.57.58] PHP Fatal error: Uncaught exception 'RuntimeException' with message 'Error creating directory /images/avatars/uploaded' in /SITE/lib/ImageManipulator.php:223\nStack trace:\n#0 /SITE/lib/uploadimage.php(30): ImageManipulator->save('/images/avatars...')\n#1 {main}\n thrown in /SITE/lib/ImageManipulator.php on line 223, referer: SITE/index.php 

답변

0

그것은 기반의 허가 및 이미지 디렉토리에있는 작은 오류였다에게 것으로 보인다.

www .. data가 소유해야 할 ../images 및 폴더가 있어야합니다.

관련 문제