Đang tải dữ liệu...
18:28

[PHP]dynamic image uploading :: automatic create file uploading field

<html> <head> </head> <title> Dynamic Image Uploading :: Automatic Create File Uploading Field</title> <head> <script type="text/javascript" src="js/jquery-1.4.2.js"></script> <script type="text/javascript" src="js/jquery-ui-1.8.custom.min.js"></script> <script type="text/javascript"> $(function(){ $("a:[id=createNew]").bind("click",function(){ var CounterLimit = 10; var LastDivId = $("div:[id=FileUploadDiv]:last").attr("DivValue"); var appandingDiv = $("div:[id=FileUploadDiv][DivValue="+LastDivId+"]"); var NewDivId = eval(LastDivId)+1; if(CounterLimit>NewDivId){ var NewUploadDiv = "<div align='left' id='FileUploadDiv' DivValue='"+NewDivId+"' style='display: none'>"+ "<input name='filename"+NewDivId+"' type='file' id='filename'>"+ "</div>"; var UploadDivCounter =eval($("#counter").val())+1; $("#counter").val(UploadDivCounter); $(NewUploadDiv).clone().show().appendTo(appandingDiv); } else { var AlertMessage= "You Can upload maximum "+CounterLimit+" Files!"; alert(AlertMessage); } return false; }); }); </script> <style type="text/css"> </style> </head> <body> <form method='post' action='multi_upload_now.php' enctype='multipart/form-data'> <div id="upload_box_wrapper"> <div id="upload_title_text">Upload Image:</div> <div id="FileUploadDiv" DivValue="0"> <input name='filename0' type='file' id='filename'> </div> <p class="add-new-upload-box"> <a href="#" id="createNew" class="add-new-upload-link">Add More </a> </p> <input type="hidden" value="0" id="counter" name="counter"> <div align='left'> Upload Image: <input type='submit' name='submit' value='Upload Now!' class="upload-button"> </div> </div> </form> </body> </html> multi_upload_now.php<a href="multi_upload.php">Upload Again</a> <?php require_once 'upload_config.php'; if($clear_folder_before_upload){ $mydirectory = myUploadDir(); EmptyDir($mydirectory); } $uploaded_file_counter=0; $UploadLimit = $_POST['counter']; for($i=0;$i<=$UploadLimit;$i++){ $file_tag='filename'.$i; $filename=$_FILES[$file_tag]['name']; if($filename!=null) { $rand=time(); $str="$rand$filename"; // set folder name in here. $filedir= myUploadDir(); //change the string format. $string= $filedir.$str; $patterns[0] = "/ /"; $patterns[1] = "/ /"; $patterns[1] = "/ /"; $replacements[1] = "_"; $dirname=strtolower(preg_replace($patterns, $replacements, $string)); //end of changing string format //checking the permitted file types if($check_file_extentions) { $allowedExtensions = allowedfiles(); foreach ($_FILES as $file) { if ($file['tmp_name'] > '') { if (!in_array(end(explode(".", strtolower($file['name']))), $allowedExtensions)) { $fileUploadPermission=0; } else { $fileUploadPermission=1; } } } } else{ $fileUploadPermission=1; } //end of checking the permitted file types if($fileUploadPermission){ if(move_uploaded_file($_FILES[$file_tag]['tmp_name'],$dirname)) { echo "<p>"; echo "<img src='$dirname'>"; echo "</p>"; $uploaded_file_counter+=1; } } } } if($uploaded_file_counter==0){ echo "<br /> <b style='font-weight:bold;color:red'>Opss! Please select an image file<b>"; }else{ echo "<br /> <b>You request ".$i." image files to upload and ".$uploaded_file_counter. " files uploaded sucessfully</b>"; } ?>

Full Code http://dl.dropbox.com/u/133097466/Code%20Php/CodeIgniter_Image_Uploader_Modules.zip http://dl.dropbox.com/u/133097466/Code%20Php/multiple_file_upload.zip

0 nhận xét

Leave a reply

Like Me On Facebook

Bài Đăng Mới

Quảng Cáo