Jump to content
php.lv forumi

Ajax Upload


sandrulis

Recommended Posts

Sveiki! neliela problēma saistībā ar ajax upload.

 

Izmantoju tikai ar javascript failu:

(function () {
	var input = document.getElementById("images"), 
		formdata = false;

	if (window.FormData) {
    formdata = new FormData();
    document.getElementById("btns").style.display = "none";
	}
	
 	input.addEventListener("change", function (evt) {
 		var i = 0, len = this.files.length, img, reader, file;
	
		for ( ; i < len; i++ ) {
			file = this.files[i];
	
			if (!!file.type.match(/image.*/)) {
				if ( window.FileReader ) {
					reader = new FileReader();
					reader.onloadend = function (e) { 
						showUploadedItem(e.target.result, file.fileName);
					};
					reader.readAsDataURL(file);
				}
				if (formdata) {
					formdata.append("images[]", file);
				}
			}	
		}
	
		if (formdata) {
			$.ajax({
				url: "upload.php",
				type: "POST",
				data: formdata,
				processData: false,
				contentType: false,
				success: function (html) {
				$("#images_list").append(html);
				$('#images').attr({ value: '' });
				}
			});
		}
	}, false);
}());

un problēma ir tāda, ka augšuplādējot vienu bildi viss ok, bet kad gribu norādīt vēl vienu tad viņš augšuplādē atkal iepriekšējo un tad atkal norādīto?

 

kur ir problēma?

Lai neaugšuplādētu atkal jau iepriekš norādīto attēlu?

 

Ceru ka sapratāt un paldies jau iepriekš

 

P.s.

 

Upload.php fails:

<?
foreach ($_FILES["images"]["error"] as $key => $error) {
  if ($error == UPLOAD_ERR_OK) {
    $name = $_FILES["images"]["name"][$key];
    move_uploaded_file( $_FILES["images"]["tmp_name"][$key], "uploads/" . $_FILES['images']['name'][$key]);
    print "uploads/" . $_FILES['images']['name'][$key] . "<br>";
  }
}
?>
Edited by sandrulis
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...