2013-01-17 24 views
0

我试图将我的数据库行ID从此表单发送到uploadify.php,以便它可以使用文件名更新该行,但是当我运行时不会发生这种情况与插入相同的脚本,并将任何ID输入到所需数据行下方的行中。我该怎么做,请帮忙。如何将数据从我的表单发送到uplodify.php

这是我form.php的

<!DOCTYPE HTML> 
    <html> 
    <head> 
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> 
    <title>UploadiFive Test</title> 
    <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script> 
    <script type="text/javascript" src="Upl/jquery.uploadify.min.js"></script> 
    <link rel="stylesheet" type="text/css" href="Upl/uploadify.css" /> 
    <style type="text/css"> 
    body { 
     font: 13px Arial, Helvetica, Sans-serif; 
    } 
    </style> 
    <?php 
    include ('lId.php') 
    ?> 
     <script type="text/javascript"> 
     $(function() { 
     $('#imgUpload').uploadify({ 
      'auto'  : false, 
      'swf'  : 'Upl/uploadify.swf', 
      'uploader' : 'Upl/uploadify.php', 
      'height' : 20, 
      'width' : 200, 
      'fileTypeDesc' : 'Image Files', 
      'fileTypeExts' : '*.gif; *.jpg; *.png', 
      'method' : 'POST', 
      'scriptData' : {'iD' : "<?php echo $tId; ?>" },   
      // Put your options here 
     }); 
    }); 
     </script> 

    </head> 

    <body> 
     <h1>Uploadify Demo</h1> 
     <p> 
     <label for="poiid">ID :</label> 
     <input type="text" name="poiid" id="poiid" readonly="readonly" style="width:70px;" value="<?php echo $tId; ?>" /> 
     </p> 
     <form enctype="multipart/form-data" method="POST"> 
      <div id="queue"></div> 
      <input id="imgUpload" name="imgUpload" type="file" multiple="true" /> 
      <a href="javascript:$('#imgUpload').uploadify('upload','*')">Upload Files</a> 
     </form> 


    </body> 
    </html> 

我upldify.php

<?php 
/* 
Uploadify 
Copyright (c) 2012 Reactive Apps, Ronnie Garcia 
Released under the MIT License <http://www.opensource.org/licenses/mit-license.php> 
*/ 

include ('../../POIWeb/connect.php'); 


// Define a destination 
$sId = $_REQUEST['iD']; 
$path = 'POIWeb/img/'; 
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $path ; // Relative to the root 

/*$verifyToken = md5('unique_salt' . $_POST['timestamp']); 

if (!empty($_FILES) && $_POST['token'] == $verifyToken) { 
    $tempFile = $_FILES['Filedata']['tmp_name']; 
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder; 
    $targetFile = rtrim($targetPath,'/') . '/' . $_FILES['Filedata']['name']; 

    // Validate the file type 
    $fileTypes = array('jpg','jpeg','gif','png'); // File extensions 
    $fileParts = pathinfo($_FILES['Filedata']['name']); 

    if (in_array($fileParts['extension'],$fileTypes)) { 
     move_uploaded_file($tempFile,$targetFile); 

     echo $fName; 
     echo '1'; 
    } else { 
     echo 'Invalid file type.'; 
    } 
}*/ 

if (!empty($_FILES)) { 
    $tempFile = $_FILES['Filedata']['tmp_name']; 
    $targetFile = $targetPath . $_FILES['Filedata']['name']; 

    // Validate the file type 
    $fileTypes = array('jpg','jpeg','gif','png'); // File extensions 
    $fileParts = pathinfo($_FILES['Filedata']['name']); 

    if (in_array($fileParts['extension'],$fileTypes)) { 
     move_uploaded_file($tempFile,$targetFile); 

     $fName = $_FILES['Filedata']['name']; 
     //$imgPath = "INSERT INTO poiinfo(`Img`) VALUES ('$fName')"; 
     $imgPath = "UPDATE poiinfo SET Img = '$fName' WHERE ID = '$sId'"; 
     mysql_query($imgPath); 
     echo '1';  

    } else { 
     echo 'Invalid file type.'; 
    } 
} 
?> 
+0

有人可以帮我 –

回答

0

使用 'FORMDATA' 而不是 'scriptData'。并获取$ _POST数组中的数据。

此代码<a href="javascript:$('#imgUpload').uploadify('upload','*')">Upload Files</a>不需要

但uploadify上传文件直接 - 这意味着你需要添加文件的下一个名字,不重写。

相关问题