我正在尝试使用 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";
}
}
?>
最佳答案
也许这个插件可以帮助你:
关于php - jQuery uploadify 将图片存储到mysql,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13426712/