2017-02-13 1 views
0

나는 웹 사이트를 만들고 있으며 새 게시물을 추가하는 양식이 있습니다. 나는 IE에 대한 전폭적 인 지원을 위해 아약스 대신 iFrame을 사용하고있다. (좋아, IE는 가장 싫어하고 최악의 브라우저 중 하나이지만 일부 멍청이는 그것을 사용하고있다.) 기본적으로 양식을 제출하면 내부 오류가 발생합니다 (500).PHP로 업로드

<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/ionic/1.3.2/css/ionic.min.css"> 
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
<form enctype="multipart/form-data" class="form" id="form" action="./addPost.php" method="POST"> 
     <div class="list"> 
      <label class="item item-input"> 
      <input type="text" placeholder="Title" class="AddPosttitle" name="title"> 
      </label> 
      <label class="item item-input"> 
      <input class="description" type="text" placeholder="Simple Description (max 60 caracters)" maxlength="60" name="description"> 
      </label> 
      <label class="item item-input"> 
      <div> 
       <span id='button_upload'>Image : </span> 
       <input type='file' class="img" name="img"> 
      </div> 
      </label> 
      <label class="item item-input"> 
      <textarea placeholder="Full description" class="full" name="full"></textarea> 
      </label> 
      <div class="padding"> 
       <button class="button button-block button-positive submit-btn" type="submit"> 
       Submit 
      </button> 
      </div> 
     </div> 
    </form> 
    <style type="text/css"> 
     .form { 
      background: #FFF; 

     } 
    </style> 
    <?php 
    if (!empty($_GET['error'])){ 
     ?> 
     <script type="text/javascript"> 
      function findGetParameter(parameterName) { 
       var result = null, 
        tmp = []; 
       var items = location.search.substr(1).split("&"); 
       for (var index = 0; index < items.length; index++) { 
        tmp = items[index].split("="); 
        if (tmp[0] === parameterName) result = decodeURIComponent(tmp[1]); 
       } 
       return result; 
      } 
      alert(findGetParameter("error")); 
     </script><?php 
    } 
    ?> 

나는 일부 구성 요소를 사랑해서, 이오니아 라이브러리를 사용하고 있지만, 어쨌든이 내 addPost.php 파일입니다 :

<?php 
try 
{ 
    $db = new PDO('mysql:host=something;dbname=someDB;charset=utf8', 'ID', 'LOL'); 
} 
catch(Exception $e) 
{ 
    die('Erreur : '.$e->getMessage()); 
} 

$post = $_POST; 
$img = base64_encode(file_get_contents($_FILES['img']['tmp_name'])); 
$title = addslashes($post['title']); 
$description = addslashes($post['description']); 
$fullDesc = addslashes($post['full']); 
// if (!empty($title) & !empty($description) & !empty($fullDesc) & !empty($img)) { 

// } 
// else { 
// // header("Location: form.php?error=Fill the form!"); 
// } 

$sql = "INSERT INTO posts (title, description, img, fullDesc, likes) VALUES ('$title', '$description', hextoraw('$img')', '$fullDesc', 0)"; 
$db->exec($sql); 
    // header("Access-Control-Allow-Origin: *"); 
header("Location: form.php?error=$sql"); 

내가 왜 모르는 여기 내 양식입니다 오류가 있습니다. 나는 이미지에서 오는 것이라고 생각하지만 확실하지 않습니다. 나는 여전히 궁극적 인 해결책을 찾으려고 노력 중이다. 무언가를 찾으면 내 질문을 편집한다.

+0

게시물에 삽입 할 때 추가 인용이 있습니다. 당신에게 알려주기 위해서. – Nello

+1

'hextoraw'가 무엇이든 문자열을 사용하여 함수를 호출 할 수 없습니다. –

답변

0
당신은 정말 보안을 위해 prepared statements를 사용한다

:

$stmt = $db->prepare("INSERT INTO posts (title, description, img, fullDesc, likes) VALUES (:title, :description, :img, :fullDesc, :likes)"); 

$stmt->bindParam(':title', $title); 
$stmt->bindParam(':description', $description); 
$stmt->bindParam(':img', hextoraw($img)); 
$stmt->bindParam(':fullDesc', $fullDesc); 
$stmt->bindParam(':likes', 0); 

$stmt->execute(); 

이는 쉽게 재사용 할 수있는 문장을 작성하여 도움을 줄 수 있습니다 (링크 참조).

+0

예기치 않은 문제가 있습니다. 다음과 같은 오류 메시지가 나타납니다. '치명적 오류 : 캐치 오류 : /api/addPost.php30에서 참조로 매개 변수 2를 전달할 수 없습니다. 스택 추적 # 0 {main}은/api/addPost입니다. php on line 30' 30 행은'$ stmt-> bindParam (': likes', 0);' –

0

표시되는 500 오류가 스택 추적 또는 자세한 오류 메시지없이 일반 오류 페이지 인 경우), 웹 서버의 오류 로그 파일의 마지막 행을 찾아 여기에 게시하십시오. 오류에 대한 자세한 정보가 필요합니다. 어쩌면 파일 액세스 오류일까요? 데이터베이스 오류 ?

또한 HEXTORAW Oracle 함수를 사용하여 16 진수 문자열을 2 진수 데이터로 변환하는 경우 HEXTORAW는 base 64로 인코딩 된 문자열이 아니라 hexstring으로 작동한다는 점을 알아야합니다. base64_encode 대신 http://php.net/manual/en/function.bin2hex.php을 사용해야합니다.

0

당신은 SQL 문자열의 미스 프린트가 : HEXTORAW ('$의 IMG') '

제거 마지막으로 견적을