jquery.uploadify php,php – JQuery uploadify将图像存储在mysql中

我试图使用uploadify将多个图像插入到

mysql数据库中.

我的数据库有一个类型为longblob的列.

每次我选择多个文件时,只有我的第一个图像被成功插入.我设置了multi = true.我无法插入多个图像,每当我点击上传链接时,onComplete事件都不会被执行.没有显示错误.

由于某种原因,我的脚本无法插入多个图像,因此我的上传完成事件未被调用.

我遇到的大多数例子都没有插入实际图像,只是将文件名的路径插入到数据库中.任何人都可以帮助我让我的脚本将多个图像上传到数据库中吗?

这是我的index.php脚本:

$(document).ready(function() {

//alert('I am ready to use uploadify!');

$("#picture").uploadify({

'uploader': 'uploadifyit/uploadify.swf',

'script': 'sqlupload.php',

'cancelImg': 'uploadifyit/cancel.png',

'folder': 'uploads',

'auto': false, // use for auto upload

'multi': true,

'queueSizeLimit': 4,

'sizeLimit': 10000000,

'onQueueFull': function(event, queueSizeLimit) {

alert("Please don't put anymore files in me! You can upload " + queueSizeLimit + " files at once");

return false;

},

'onAllComplete' : function(){

alert("Thank you. All files have been uploaded successfully.");

},

'onComplete': function(event, ID, fileObj, response, data) {

console.log(response); // If you're using firebug

alert(response); // Will alert the php error

},

'onUploadError' : function(file, errorCode, errorMsg, errorString) {

alert('The file ' + file.name + ' could not be uploaded: ' + errorString);

}

});

});

sqlupload.php

mysql_connect("localhost", "root", "")or die(mysql_error());

mysql_select_db("project") or die(mysql_error());

if (!empty($_FILES)) {

$fileTypes = array('jpg','jpeg','gif','png'); // File extensions

$fileParts = pathinfo($_FILES['Filedata']['name']);

if (in_array(strtolower($fileParts['extension']),$fileTypes)) {

$pic_name = $_FILES['Filedata']['name'];

$pic_size = $_FILES['Filedata']['size'];

$pic_type = $_FILES['Filedata']['type'];

$imgData =addslashes(file_get_contents($_FILES['Filedata']['tmp_name']));

// our sql query

$sql = "INSERT INTO photos (name,type,size,image) VALUES('$pic_name','$pic_type','$pic_size','$imgData')";

// insert the image

mysql_query($sql) or die("Error in Query: " . mysql_error());

}

else {

echo "Invalid file type";

}

}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值