2011-05-06 2 views
0

제가 사용중인 웹 서버에서 PHP에 문제가 있습니다. 대답은 확실하지만 확실한 이유는 나를 완전히 빠져 나가는 것입니다.PHP에 문제 (로컬 호스트에서 작동하지만 웹 서버의 오류)

나는 클라이언트의 이전 및 이후의 두 파일을 업로드하는 PHP 파일이 있습니다. 내 서버의 스크립트 (localhost)가 제대로 작동하고, 파일을 업로드하고, 파일 이름을 타임 스탬프로 변경하고, 다른 스크립트로 더 정렬 할 수 있도록 이미지를 폴더에 저장합니다.

그러나 웹 서버에 파일을 업로드 할 때 일부 파일 (예 : mel.jpg, test.jpg)이 작동하지만 IMG_0042.jpg와 같은 파일이 작동하지 않으면 답변이 간단하지만 확실한 답을 얻지 못합니다. .

언더 스코어가 그와 관련이 있을지 모르지만, 내 인생을 위해 그것을 할 수는 없다고 생각합니다. 어떤 도움도 크게 감사합니다. 대단히 감사합니다.

<?php 

if(!isset($_COOKIE['auth'])) { 
header("Location: login12.php"); 
exit(); 
} 

$page_title="test"; 
include('header.html'); 

// Upload and Rename File 

if (isset($_POST['submitted'])) { 
$filenamebef = $_FILES["uploadbef"]["name"]; 
$filenameaft = $_FILES["uploadaft"]["name"]; 
$file_basename_bef = substr($filenamebef, 0, strripos($filenamebef, '.')); 
$file_basename_aft = substr($filenameaft, 0, strripos($filenameaft, '.')); 
// get file extention 
$file_ext_bef = substr($filenamebef, strripos($filenamebef, '.')); 
$file_ext_aft = substr($filenameaft, strripos($filenameaft, '.')); 
// get file name 
$filesize_bef = $_FILES["uploadbef"]["size"]; 
$filesize_aft = $_FILES["uploadaft"]["size"]; 
$allowed = array('image/pjpeg','image/jpeg','image/JPG','image/X-PNG','image/PNG','image /png','image/x-png'); 

    if ((in_array($_FILES['uploadbef']['type'], $allowed)) && in_array($_FILES['uploadaft']['type'], $allowed)) {  

     if (($filesize_bef < 200000) && ($filesize_aft < 200000)){ 

      // rename file 

      $date = date("mdy"); 
      $time = date("His"); 

      $timedate = $time . $date; 

      $newfilenamebef = $timedate . $file_ext_bef; 
      $newfilenameaft = $timedate . $file_ext_aft; 

      if ((file_exists("upload/images/before" . $newfilenamebef)) && (file_exists("uploads/images/after" . $newfilenameaft))) {  
       // file already exists error 
       echo "You have already uloaded this file.";   
      } else {   
       move_uploaded_file($_FILES["uploadbef"]["tmp_name"], "uploads/images/before/" . $newfilenamebef) && move_uploaded_file($_FILES["uploadaft"]["tmp_name"], "uploads/images/after/" . $newfilenameaft); 
       echo "File uploaded successfully."; 

      } 
     } 

    } elseif ((empty($file_basename_bef)) && (empty($file_basename_aft))) { 
     // file selection error 
     echo "Please select a file to upload.";  
    } elseif (($filesize_bef > 200000) && ($filesize_aft > 200000)) { 
     // file size error 
     echo "The file you are trying to upload is too large.";  
    } else {  
     // file type error 
     echo "Only these file typs are allowed for upload: " . implode(', ',$allowed); 
     unlink($_FILES["uploadbef"]["tmp_name"]); 
     unlink($_FILES["uploadaft"]["tmp_name"]); 
    } 

} 

echo $newfilenamebef; 
echo $newfilenameaft; 

?> 



<form enctype="multipart/form-data" action="uploading.php" method="post"> 

<input type="hidden" value="MAX_FILE_SIZE" value="524288"> 
<fieldset> 
<legend>Select a JPEG or PNG image of 512kb or smaller to be uploaded : </legend> 
<p><b>Before</b> <input type="file" name="uploadbef" /></p> 
<p><b>After</b> <input type="file" name="uploadaft" /></p> 
</fieldset> 

<div align="center"><input type="submit" name="submit" value="Submit" /></div> 
<input type="hidden" name="submitted" value="TRUE" /> 

</form> 

<?php 
include('footer.html'); 
?> 
+0

당신은 밑줄이 문제를 생각한다면, 밑줄없이 해당 파일의 이름을 변경하고 다시 시도 - 그것은 또는 문제의 범위를 좁히는 데 도움이되지 않을 경우 적어도 다음 확인할 수 있습니다. – Dave

+1

"일하지 않는다"는 것은 무엇을 의미합니까? 오류 메시지가 나타 납니까? 이 파일들의 차이점은 무엇입니까 (파일명 제외)? – Ikke

+0

max_upload_filesize를 확인하고 원격 호스트에 크기를 게시하십시오. – Damien

답변

3

당신해야하지만 당신의 index.php 또는 bootstrap.php의 상단에 다음 두 줄 :

error_reporting(-1); 
ini_set("display_errors" , 1); 

그리고 일부 오류 메시지가 켜 있는지 확인합니다.

잘못된 파일 권한으로 인해 문제가 발생할 가능성이 큽니다.

+0

+1로 php.ini 대신 스크립트에 추가 할 것을 제안합니다. (어디에서 자주 잊어 지는지) –

1

웹 서버가있는 반면 localhost는 대소 문자를 구분하지 않는다고 생각하면됩니다.

즉, 로컬 호스트에서 IMG_12345.JPG는 img_12345.jpg와 동일합니다. 귀하의 웹 서버에, 그들은 다르게 취급됩니다.

실제로보고 된 오류가 없지만 확실하지는 않으나 이는 일반적인 문제입니다.

+0

안녕하세요. 빠른 답변! 그것을 시도하고 그것이 어떻게되는지 보게 될 것입니다. – Nik

0

올바른 업로드를 제대로 확인하지 않습니다. 다음과 같은 것이 훨씬 더 신뢰할 수있는 것입니다 :

// this value is ALWAYS present and doesn't depend on form fields 
if ($_SERVER['REQUEST_METHOD'] == 'POST') { 
    $errmsgs = array(); 
    if ($_FILES['uploadbef']['error'] !== UPLOAD_ERR_OK) { 
     $errs++; 
     $errmsgs[] = "'uploadebef' failed with code #" . $_FILES['uploadebef']['error']; 
    } 
    if ($_FILES['uploadaft']['error'] === UPLOAD_ERR_OK) { 
     $errs++; 
     $errmsgs[] = "'uploadeaft' failed wicode #" . $_FILES['uploadeaft']['error']; 
    } 
    if (count($errmsgs) > 0) { 
     print_r($errmsgs); 
     die(); 
    } 
    ... process the files here ... 
} 

마찬가지로 파일 이름을 나누기 위해 휠을 다시 만드는 이유는 무엇입니까?

$parts = path_info($_FILES['uploadaft']['name']); 
$basename = $parts['basename']; 
$ext = $parts['extension']; 
+0

어쨌든 그 제안에 감사 드리며, 스크립트에 그들을 구현하려고합니다. 파일 이름의 분할이 훨씬 쉬워 보이고, 내가 가진 모든 초과 코드를 다시 보게됩니다. 다시 한번 감사드립니다. – Nik

관련 문제