0

我正在尝试将我的数据库行 ID 从此表单发送到uploadify.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.';
    }
}
?>
4

1 回答 1

0

使用“formData”而不是“scriptData”。并获取 $_POST 数组中的数据。

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

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

于 2013-01-22T08:20:16.940 回答