Jump to content
php.lv forumi

ajax upload


ziedinjsh

Recommended Posts

nesaprotu kapēc neiet:

 

headrī

<script type="text/javascript" >
$(function(){
	var btnUpload=$('#upload');
	var status=$('#status');
	new AjaxUpload(btnUpload, {
		action: 'fcs/upload.php',
		name: 'avatar',
		onSubmit: function(file, ext){
			 if (! (ext && /^(jpg|png|jpeg|gif)$/.test(ext))){ 
                   // extension is not allowed 
				status.text('Only JPG, PNG or GIF files are allowed');
				return false;
			}
			status.html('<img src="img/loader.gif">');
		},
		onComplete: function(file, response){
			//On completion clear the status
			status.text('');
			//Add uploaded file to list
			if(response==="success"){
				$('<li></li>').appendTo('#files').html('<img src="avatars/'+file+'" alt="" /><br />'+file).addClass('success');
			} else{
				$('<li></li>').appendTo('#files').text(file).addClass('error');
			}
		}
	});

});
</script>

 

upload.php:

$uploaddir = 'avatars/'; 
$file = $uploaddir . basename($_FILES['avatar']['name']); 


if (move_uploaded_file($_FILES['avatar']['tmp_name'], $file)) { 
 echo "success"; 
} else {
echo "error";
}

 

bet bildes viņš nelādē iekšā!

Link to comment
Share on other sites

Nav ne jausmas kas tas par AjaxUpload un kādēļ tur to vispār vajag + kādēļ tam vajag izpildīties pie document.ready nevis pie pogas nospiešanas, piemēram + vēl daudz kas, bet nu lai vai kā...ar AJAX upload'ēt nevar.

 

Šaubos vai pats to esi rakstītjis. Mēģini vismaz domāt līdzi tam ko kopē...

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...