2013-03-12 5 views
0

그래서 나는 형태의 결과를 소요 PHP에서이 코드를 가지고 :는 PHP를 통해 서버에 이미지를 업로드 실패

<?php if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) 
{ 
    $fileName = $_FILES['userfile']['name']; 
    $tmpName = $_FILES['userfile']['tmp_name']; 
    $fileSize = $_FILES['userfile']['size']; 
    $fileType = $_FILES['userfile']['type']; 

    $path = $_SERVER['DOCUMENT_ROOT'] . "/uploads/"; 
    //$path = "uploads/"; 
    $path = $path . basename($_FILES['userfile']['name']); 

    is_uploaded_file($_FILES['userfile']['tmp_name']) or error('not an HTTP upload'); 

    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $path)) 
    { 
     echo "The file ". basename($_FILES['userfile']['name']) . " has been uploaded, and your information has been added to the directory"; 
    } 
    else 
    { 
     echo "Sorry, there was a problem uploading your file -->" . $path; 
    } 


    } ?> 

내가 가진 문제는 코드가 is_uploaded_file을 통과하지만 move_uploaded_file

을 실행할 때 실패하다

이 코드는 많은 PHP 포럼 및 자습서에서 찾은 코드입니다.

누구나 내 서버에 업로드되지 않는 이유를 알 수 있습니다.

편집 :

<!DOCTYPE html> 
<html> 
<head> 
    <title>Montréal Accessible</title> 
    <meta name="viewport" content="initial-scale=1.0, user-scalable=no"/> 
    <meta charset="UTF-8"> 
    <link rel="stylesheet" type="text/css" href="vendors/bootstrap/css/bootstrap.min.css"/> 
    <link rel="stylesheet" href="http://code.jquery.com/ui/1.10.0/themes/base/jquery-ui.css"> 
    <link rel="stylesheet" type="text/css" href="stylesheets/home.css"/> 
    <link rel="stylesheet" type="text/css" href="stylesheets/grid.css"> 
    <script type="text/javascript" src="https://maps.googleapis.com/maps/api/js?key=AIzaSyD9wqmeX_YlaRLZYrnNDOkHcXvlXa9cATo&sensor=false"></script> 
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> 
    <script src="http://code.jquery.com/ui/1.10.0/jquery-ui.js"></script> 
    <script type="text/javascript" src="scripts/home.js"></script> 

    <?php if(isset($_POST['upload']) && $_FILES['userfile']['size'] > 0) 
    { 
     $fileName = $_FILES['userfile']['name']; 
     $tmpName = $_FILES['userfile']['tmp_name']; 
     $fileSize = $_FILES['userfile']['size']; 
     $fileType = $_FILES['userfile']['type']; 

     $path = $_SERVER['DOCUMENT_ROOT'] . "/uploads/"; 
     //$path = "uploads/"; 
     $path = $path . basename($_FILES['userfile']['name']); 

     is_uploaded_file($_FILES['userfile']['tmp_name']) or error('not an HTTP upload'); 

     if (move_uploaded_file($_FILES['userfile']['tmp_name'], $path)) 
     { 
      echo "The file ". basename($_FILES['userfile']['name']) . " has been uploaded, and your information has been added to the directory"; 
     } 
     else 
     { 
      echo "Sorry, there was a problem uploading your file -->" . $path; 
     } 

     $myvars = ''; 
     $ch = curl_init($url); 
     curl_setopt($ch, CURLOPT_POST, 1); 
     curl_setopt($ch, CURLOPT_POSTFIELDS, $myvars); 
     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
     curl_setopt($ch, CURLOPT_HEADER, 0); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

     $upImgResponse = curl_exec($ch);*/ 
    } ?> 

    <script type="text/javascript"> 
     window.onload = function() 
     { 
      loginForm = document.forms[0]; 
      loginForm.onsubmit=function() 
      { 
       var name = prompt ("Enter your name","") 

       if(loginForm[0].value == '') 
       { 
        alert('Please enter a username'); 
        return false; 
       } 
       else 
       { 
        loginForm.action='../Symfony/web/app.php/login/' + name + '/' + ...; 
        return true; 
       } 
      } 
     } 
    </script> 

</head> 
<body> 
    <div id="container"> 
     <div id="headerBar"> 
      <div id="homeLogoColumn"> 
       <div id="homeLogo">Montréal Accessible</div> 
      </div> 
      <div id="searchBarColumn"> 
       <div id="searchBar" class="input-append"> 
        <input id="appendedInputButton" type="text"> 
        <a id="searchButton" class="btn btn-primary" href="#"><i class="icon-search icon-white"></i></a> 
       </div> 
      </div> 
      <div id="anchorsColumn"> 
         <a class="lastAnchor" href="#">À propos</a> 
         <a href="#">Contact</a> 
         <a href="#">Aide</a> 
         <!--<form name="input" action="" method="post"> 
         <a href="#">Connexion</a><input type="submit" value="Connect"> 
         </form> --> 

      </div> 
     </div> 


     <form method="post" enctype="multipart/form-data"> 
     <table width="350" border="0" cellpadding="1" cellspacing="1" class="box"> 
     <tr> 
     <td width="246"> 
     <input type="hidden" name="MAX_FILE_SIZE" value="2000000"> 
     <input name="userfile" type="file" id="userfile"> 
     </td> 
     <td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td> 
     </tr> 
     </table> 
     </form> 

     <div id="mainContent"> 
       <div id="paramsAndResultsColumn"> 
        <div id="paramsAndResultsTabs"> 
         <ul> 
         <li><a href="#paramsTab"><span>Critères</span></a></li> 
         <li><a href="#resultsTab"><span>Résultats</span></a></li> 
         </ul> 
         <div id="paramsTab"></div> 
         <div id="resultsTab"></div> 
        </div> 
       </div> 
       <div id="mapCanvasColumn"> 
        <div id="mapCanvas"></div> 
       </div> 
     </div> 
    </div> 
</body> 
</html> 

편집 2 :

표시되는 오류가 "죄송합니다, 문제 업로드가 있었다이다

여기에 HTML 코드와 전체 .PHP 파일입니다. ... "의미는 다른 사람을 통해갑니다 ...

+1

은 $ path writable입니까? 너는 주인 이니? –

+0

예 저는 소유자이고 쓰기가 가능합니다. – nevero

+0

양식 코드 게시. –

답변

0

도움 주셔서 감사합니다. 문제는 사용 권한 문제입니다. chmod 대신 chmod 755를 사용하여 폴더에 대한 사용 권한을 설정합니다. 7730

+0

기본적으로 내 서버에는 모든 폴더가 755로 설정되어 있습니다. 최악의 경우를 대비하여 777 번으로 chmod 할 수 있습니다. 다행 이네. –

0

0) { $ fileN ame = $ _FILES [ 'userfile'] [ 'name']; $ tmpName = $ _FILES [ 'userfile'] [ 'tmp_name']; $ fileSize = $ _FILES [ 'userfile'] [ 'size']; $ fileType = $ _FILES [ 'userfile'] [ 'type']; echo $ tmpName;

$path = "uploads/"; 
    $path = $path . basename($_FILES['userfile']['name']); 

    is_uploaded_file($_FILES['userfile']['tmp_name']) or error('not an HTTP upload'); 

    if (move_uploaded_file($_FILES['userfile']['tmp_name'], $path)) 
    { 
     echo "The file ". basename($_FILES['userfile']['name']) . " has been uploaded, and your information has been added to the directory"; 
    } 
    else 
    { 
     echo "Sorry, there was a problem uploading your file -->" . $path; 
    } 

    /*$url="http://rapliq.lerb.polymtl.ca/Symfony/web/app.php/upimg/" . $fileName . "/" . $path . "/"; 

    $myvars = ''; 
    $ch = curl_init($url); 
    curl_setopt($ch, CURLOPT_POST, 1); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $myvars); 
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); 
    curl_setopt($ch, CURLOPT_HEADER, 0); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 

    $upImgResponse = curl_exec($ch);*/ 
} ?>` 

이 문제는 목욕탕에서 주 뿌리 줄 필요가 없었습니다. 폴더에 액세스 할 수 있는지 확인하십시오.

+0

불행히도 그것을 해결하지 못합니다. 실제로 루트를 사용하기 전에이 방법을 사용했습니다 ... 왜냐하면 "절대 경로"가 더 좋을 것이기 때문에 – nevero

관련 문제