2010-01-29 1 views
0

업로드 스크립트를 조금만 사용해 보려고했는데 ... 할당 된 폴더에 모든 파일을 올바르게 업로드하지만 업로드에 대한 세부 정보는 mysql을 통해 추가되지 않습니다.업로드는 tempermental입니까? 데이터베이스에 새로 업로드 된 파일을 나열 할 수 없습니다!

어디에서 내가 실수를 저질렀는지 알 수 있습니까? 도와주세요.

manage.php

<script type="text/javascript"> 
    $(document).ready(function() { 
     $("#uploadify").uploadify({ 
      'uploader'  : 'resources/uploadify.swf', 
      'script'   : 'resources/uploadify.php', 
      'folder'   : 'files', 
      'queueID'  : 'fileQueue', 
      'auto'   : true, 
      'onAllComplete' : function(){ alert("Thank you. All files have been uploaded successfully."); }, 
      'multi'   : true 
     }); 
    }); 
    </script> 
    <form method="post" action="<?php echo $_SERVER['PHP_SELF'] . '?id=' . intval($client_id); ?>"> 
    <p> 
     <b>File Upload</b></p> 
<div id="fileQueue"></div> 
<input type="file" name="uploadify" id="uploadify" /> 
<p><a href="javascript:jQuery('#uploadify').uploadifyClearQueue()" class="form">Cancel all uploads</a></p> 
<a href="#viewFiles" class="form" rel="facebox">View files</a> 

<div id="viewFiles" style="display:none;" rel="facebox"> 
        <div style="width:300px; height: 300px;"></div> 
</div> 

    </p> 
</form> 

uploadify.php

<?php require_once('../Connections/speedycms.php); 

if (!empty($_FILES)) { 
    $tempFile = $_FILES['Filedata']['tmp_name']; 
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/'; 
    $targetFile = str_replace('//','/',$targetPath) . $_FILES['Filedata']['name']; 

    $fileName = $_FILES['uploadify']['name']; 
    $fileSize = $_FILES['uploadify']['size']; 
    $fileType = $_FILES['uploadify']['type']; 

     $client_id = mysql_real_escape_string($_GET['id']); 

    // $fileTypes = str_replace('*.','',$_REQUEST['fileext']); 
    // $fileTypes = str_replace(';','|',$fileTypes); 
    // $typesArray = split('\|',$fileTypes); 
    // $fileParts = pathinfo($_FILES['Filedata']['name']); 

    // if (in_array($fileParts['extension'],$typesArray)) { 
     // Uncomment the following line if you want to make the directory if it doesn't exist 
     // mkdir(str_replace('//','/',$targetPath), 0755, true); 

     move_uploaded_file($tempFile,$targetFile); 
     echo "1"; 

     mysql_query(" 
INSERT INTO tbl_accidentfiles SET client_id='$client_id', name='${fileName}', path='${targetFile}', size='$fileSize', content_type='${content_type}'"); 

    // } else { 


// echo 'Invalid file type.'; 
     // } 

    } 

?> 

많은 감사합니다!

+0

, 그것은 그 정보를 가지고 않습니다 이미지와 각각의 ID 필드와 테이블을 삽입 할 생각이있어? – Sarfraz

+0

아무 일도 일어나지 않습니다 ... – methuselah

답변

1

플래시 스크립트가 manage.php 페이지의 양식이 아닌 uploadify.php 파일을 호출 중입니다.

변경해보십시오 :

$fileName = $_FILES['uploadify']['name']; 
$fileSize = $_FILES['uploadify']['size']; 
$fileType = $_FILES['uploadify']['type']; 

에 : 게시물에 대한

$fileName = $_FILES['Filedata']['name']; 
$fileSize = $_FILES['Filedata']['size']; 
$fileType = $_FILES['Filedata']['type']; 
+0

고마워요. – methuselah

0

PHP 오류일까요? 데이터베이스 연결이 설정되지 않을 것이다으로는 mysql_query가 실행되지 않는 이유 첫 번째 줄 ...

<?php require_once('../Connections/speedycms.php); 

(작은 따옴표 누락) 할 필요가 ...

<?php require_once('../Connections/speedycms.php'); 

이 expalin 것

$client_id = mysql_real_escape_string($_GET['id']); 

하지만 근래 : uploadify.php에 당신이 있기 때문에

+0

나는 그것을 바꿨습니다 ... 아무 일도 일어나지 않습니다! – methuselah

+0

당신은 (주소 표시 줄에서) 수동으로 스크립트를 실행하고 파일 업로드 코드를 주석 처리하여 mysql 쿼리를 확인해 보았습니까? –

0

코드는, 약간의 오류가 uploadify js 코드에서 전달하지 마십시오. 이를 위해,이 코드를 사용 : 최신 uploadify에서

$("#uploadify").uploadify({ 
    'uploader'  : 'resources/uploadify.swf', 
    'script'   : 'resources/uploadify.php', 
    'folder'   : 'files', 
    'queueID'  : 'fileQueue', 
    'auto'   : true, 
    'onAllComplete' : function(){ alert("Thank you. All files have been uploaded successfully."); }, 
    'multi'   : true, 
    scriptData  : {'id': '<?php echo intval($client_id); ?>'} 
}); 

scripData의 기본 방법은 POST입니다. 그래서, 당신의 uploadify.php 파일에 $_POST['id']을 사용하거나 uploadify JS의 방법을 변경 :

'method' : 'GET' 

See here을 더 완전한 매개 변수. 나는 그것이 지금 일하기를 바란다. 대신이 작업을 수행 할 수 uploadify.php

마지막 주 :

$client_id = intval($_GET['id']); 

client_id가 유효한 값이 포함되어 있는지 확인하십시오. 다른 값이 아닌 정수 만 포함하도록하기 때문에 그냥 이스케이프하는 것보다 낫습니다.

0

고맙습니다. 사실 내 고객은 둘러보기 패키지 이미지 수를 업로드해야하며 데이터베이스에 저장하려고합니다. 이를 위해 여러 개의 업 로더를 사용해야합니다. 그래서 공통 패키지 ID를 통해 링크 된 이미지에 대해 별도의 표를 만들기로 결정했습니다. 은 당신이 쿼리를 인쇄 할 때보다

당신

관련 문제