php - 如何在 uploadify 中传递自定义值

标签 php html uploadify

在uploadify中如何将用户输入值传递给uploadify.php 这是我的代码:

           $(function() {

    $('#file_upload').uploadify({
    'buttonText' : 'BROWSE...',
    'method'   : 'post', 
    'height'   : 50, 
    'buttonCursor' : 'hand',
    'fileSizeLimit' : '100KB', 
    'formData' : {
    'title' :$('input:text[name:title]').val(),
    'about' :$('input:text[name:about]').val() },
    'auto'     : false,
    'swf'      : 'uploadify.swf',
    'checkExisting' : 'check-exists.php',
    'uploader' : 'uploadify.php',
    'onUploadSuccess' : function(file, data, response) {
    $("#message").css("display","block");
    $("#message").text("upload process completed successfully");
    setTimeout(function() {
    $('#message').fadeOut('fast');
}, 5000);
    }, 

    'onUploadError' : function(file, errorCode, errorMsg, errorString) {
       alert('The file ' + file.name + ' could not be uploaded: ' + errorString);
    }  
});



    });
    </script>
    </head>
<?php include("includes/connection.php");?>
    <body>
        <div id="page">
            <div id="header">
                <h1>Photogallery</h1>
     <?php  include("includes/navigation.php"); ?>
            </div><!--header-->

            <div id="content">

                <div id="left">

<div id="message">
</div>
<?php

 ?>     

 <table>
    <tr>
        <td>
            <P>Title:</P>
        </td>
        <td>
            <input type="text" value="" name="title" id="idtitle" />
        </td>
    </tr>
    <tr>
        <td>
            <p>About:</p>
        </td>
        <td>
            <p><input type="text" value="" name="about"  />  </p>
        </td>
    </tr>
    <tr>
        <td>
            Select Photos you want to Upload
        </td>
        <td>
            <input type="file" name="file_upload" id="file_upload" />
        </td>
    </tr>
 </table>           


<a href="javascript:$('#file_upload').uploadify('cancel')">Cancel First File</a> | <a href="javascript:$('#file_upload').uploadify('cancel', '*')">Clear the Queue</a> | <a href="javascript:$('#file_upload').uploadify('upload', '*')">Upload the Files</a>



                </div><!--left-->

这是我的 uplodify.php 文件

   <?php
require_once("includes/connection.php");

$targetFolder = '/workbench/sudeepc/photogallery/uploads' ; 
     $title=$_POST['title'];
     // $title="testtitle";
     $about=$_POST['about'];    
if (!empty($_FILES)) {
    $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);

$query="INSERT INTO `photo` ( `id` , `path` , `uname` , `title` , `about` , `date` )
VALUES ('','${targetFile}','uname','${title}','${about}',now())";       

 /*
 $query="INSERT INTO `photo` ( `id` , `path` , `uname` )
 VALUES ( '','${targetFile}', '${title}');";
 */
 mysql_query($query,$connection);


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

我想为每次上传传递标题和简介,当用户选择多张图片时,用户可以为每张图片输入标题和简介。我该如何解决这个问题?

最佳答案

  1. 如何在 uploadify 中传递自定义值:

'formData': { 'userid': $("#uid").val(), 'taskid': $("#tid").val(), 'guid': $("#guid").val() },

  1. 有什么方法可以获取上传队列中的图片数量吗? - onDialogClose 你可以像这样访问队列:

'onDialogClose':函数(queueData){ 警报(queueData.filesQueued + '文件排队'+ queueData.filesSelected + '选定的文件。队列中有'+ queueData.queueLength + '总文件。'); },

关于php - 如何在 uploadify 中传递自定义值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10911279/

相关文章:

php - 如何为 while 循环的第一次迭代设置 PHP 变量?

php - 使用 SWFupload 或 Uploadify 时,是否需要编辑 php.ini 设置?

javascript - 在按钮隐藏时继续上传上传?

php - 在为画廊存储图像时,最佳做法是什么?

php - Symfony 中的翻译文件不存在

php - 自定义 OAuth2 用户数据库

php adodb MSSQL 连接

PHP - 如果自动加载,为什么要使用依赖注入(inject)?

php - javascript: 引号问题: &lt;input ... onclick ='....value=\' 2011-01-07 19:37\';' > 不起作用?

html - 我的图标没有向右浮动