ajax图像上传和发送变量

时间:2014-12-02 22:17:58

标签: php ajax image variables upload

我有ajax将信息发送到upload.php文件

一切正常,但我需要发送id以及ajax上传数据......

我试图玩数组,但我没有成功。

我的ajax如下 -

// image transfer
// Verify server has been entered
server = document.getElementById('serverUrl').value;
if (server) {
    // Specify transfer options
    var options = new FileUploadOptions();
    options.fileKey = "file";
    options.fileName = imagefile.substr(imagefile.lastIndexOf('/') + 1);
    //alert (options.fileName);
    options.mimeType = "image/jpeg";
    options.chunkedMode = false;
    // Transfer picture to server
    var ft = new FileTransfer();
    ft.upload(imagefile, server, function(r) {
        $('#example3').hide();
        document.getElementById('camera_status').innerHTML = "Image Upload successful ";
        $('#done').show();
        //})
        document.getElementById('camera_status').innerHTML = "Data Upload successful ";
    }, function(error) {
        document.getElementById('camera_status').innerHTML = "Upload Successfull" + error.code;
        ;
    }, options);
}
//image transfer end

作为接收upload.php我有以下

<?php

// Directory where uploaded images are saved
$dirname = "upload/"; 

// If uploading file
if ($_FILES) {
    print_r($_FILES);
    mkdir ($dirname, 0777, true); 
    move_uploaded_file($_FILES["file"]["tmp_name"],$dirname."/".$_FILES["file"]["name"]);
}
?>

0 个答案:

没有答案