I want to use uploadify to upload my multiple images.
What is scenario
I want to upload multiple images. I also want to enter the information of each uploaded image in database as well. As at `oncomplete event I want to get the ids of all newly entered ids of table
What I have done my uploadify code
$(document).ready(function() {
$('#fileid').uploadify({
'uploader' : '<?php echo SITEURL;?>/admin/uploadify/uploadify.swf',
'script' : '<?php echo SITEURL;?>/admin/action_files/area_pics_upload.php',
'cancelImg' : '<?php echo SITEURL;?>/admin/uploadify/cancel.png',
//'folder' : '<?php echo SITEURL;?>/admin/uploadify/uploads',
'auto': 'true',
'fileExt' : '*.jpeg;*.jpg;*.gif;*.png',
'fileDesc' : 'Image Files (*.JPEG,*.JPG, *.GIF, *.PNG)',
'multi' : true,
'onAllComplete': function(event, data)
{ alert(data); }
});
});
Code in area_upload_pics.php
if (!empty($_FILES))
{
$allowedExtensions = array("jpeg","jpg","gif","png");
for($i=0;$i<count($_FILES);$i++)
{
if(in_array(end(explode(".",strtolower($_FILES['fileid'][$i]['name']))),$allowedExtensions))
{
$file = time().'-'.$_FILES["fileid"][$i]['name'];
if(move_uploaded_file($_FILES["fileid"][$i]["tmp_name"],'../../uploaded_files/area_pics/'.$file)
{
//save file info in database
$q = "INSERT INTO ".DB_PREFIX."_files (file) values (".$file.")";
mysql_query($q);
$images_ids[]=mysql_insert_id();
}
}
}
}
echo(json_encde($images_ids);
My Problem
Images are not being uploaded. I haved checked the paths that are good. What amI doing wrong.
I was having wrong concept about uploadify. I was thinking that it hits single time to uploading resource(file doing uploading) so we have to have $_FILES
as array. But the uploadify hits the uploading script as many times as you have selected the files to upload. For example you have selected 6 files to upload. Uploadify will hit your uploading script stated in script
property of uploadify 6 times. So you don't need to use for loop
and iterate through $_FILES
. Just use the script as you use for single file uploading.
This is for those having same problem. :-)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.