1 Replies - 2529 Views - Last Post: 28 October 2011 - 05:34 AM

#1 noorahmad   User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

PHP and jQuery: Upload unlimited files

Posted 31 July 2009 - 10:00 PM

Description: this snippet will help you how to upload unlimited files just with a few line of codes
<?php
if(isset($_POST['btnSend'])){
$num = count($_FILES['upload']['name']) - 1;
for($i=0;$i<$num;$i++){
	$name = $_FILES['upload']['name'][$i];
	$tmp  = $_FILES['upload']['tmp_name'][$i];
	$path = "files/$name";
	if(!move_uploaded_file($tmp,$path)){
		echo "<p style='color:red'>File: $name not uploaded</p>";
	}else{
	echo "<p style='color:green'>File: $name uploaded
</p>";
	}
}
}
?>
<script type='text/javascript' src='jquery.js'></script>
<script type='text/javascript'>
function add(){
	$(document).ready(function(){
		$("#lbl").before("<input type='file' name='upload[]' id='upload[]' onchange='add()' />
");
	});
}
window.load(add());
</script>

<form id='frmUploadFiles' name='frmUploadFiles' action='<?PHP echo $_SERVER['PHP_SELF'];?>' method='post' enctype="multipart/form-data">
<label id='lbl'></label>
<button type='submit' id='btnSend' name='btnSend' onclick='x()'>Upload</button>
</form>


Is This A Good Question/Topic? 0
  • +

Replies To: PHP and jQuery: Upload unlimited files

#2 noorahmad   User is offline

  • Untitled
  • member icon

Reputation: 209
  • View blog
  • Posts: 2,290
  • Joined: 12-March 09

Re: PHP and jQuery: Upload unlimited files

Posted 31 July 2009 - 10:00 PM

Description: this snippet will help you how to upload unlimited files just with a few line of codes
<?php
if(isset($_POST['btnSend'])){
$num = count($_FILES['upload']['name']) - 1;
for($i=0;$i<$num;$i++){
	$name = $_FILES['upload']['name'][$i];
	$tmp  = $_FILES['upload']['tmp_name'][$i];
	$path = "files/$name";
	if(!move_uploaded_file($tmp,$path)){
		echo "<p style='color:red'>File: $name not uploaded</p>";
	}else{
	echo "<p style='color:green'>File: $name uploaded
</p>";
	}
}
}
?>
<script type='text/javascript' src='jquery.js'></script>
<script type='text/javascript'>
function add(){
	$(document).ready(function(){
		$("#lbl").before("<input type='file' name='upload[]' id='upload[]' onchange='add()' />
");
	});
}
window.load(add());
</script>

<form id='frmUploadFiles' name='frmUploadFiles' action='<?PHP echo $_SERVER['PHP_SELF'];?>' method='post' enctype="multipart/form-data">
<label id='lbl'></label>
<button type='submit' id='btnSend' name='btnSend' onclick='add()'>Upload</button>
</form>

Was This Post Helpful? 0
  • +
  • -

#3 karnash   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 0
  • Joined: 28-October 11

Re: PHP and jQuery: Upload unlimited files

Posted 28 October 2011 - 05:34 AM

where is the x() function.. ???
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1