如何从我的表单发送数据upload .php


How to send a data from my form to uplodify.php

我试图将我的数据库行ID从这个表单发送到uploadify.php,这样它就可以用文件名更新行,但它不会发生当我运行相同的脚本插入没有任何ID的名称被输入到所需的数据行下面的行。我该怎么办?请帮帮我。

这是我的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.';
    }
}
?>

使用'formData'代替'scriptData'。并在$_POST数组中获取数据。

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

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