我正在尝试使用uploadify将多个图像插入mysql数据库。我的数据库的其中一个列是 longblob 类型。每次我选择多个文件时,只有我的第一个图像被成功插入。我设置了 multi = true。我无法插入多个图像,而且每当我点击上传链接时,onComplete 事件都不会被执行。没有显示错误。由于某种原因,我的脚本无法插入多个图像,因此我的上传完成事件没有被调用。
我遇到的大多数示例,不插入实际图像,而只是将文件名的路径插入数据库。谁能帮我让我的脚本将多个图像上传到数据库中?
这是我的 index.php 脚本:
<script type="text/javascript">
$(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);
}
});
});
</script>
sqlupload.php
<?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";
}
}
?>