Worth2Read
Home

Forum

PHP Tutorials
Blogs
Children
Article Directory

Contact Us

Disclaimer
Reliable $1 Web Hosting by 3iX
 

Want to discuss this tutorial in the Forum?

Upload a file to the Server using PHP Script

First you have to give the write permission to the directory in which you are uploading the files. We are using 3 files

  • number_of_Upload : This file is for determining how many files we need to upload.
  • uploadForm : Here we select the files that are to be uploaded.
  • uploadFiles : The script to upload files.

number_of_Upload.php

<form name="form1" method="post" action="uploadForm.php">
<p>Enter the amount of boxes you will need below. Max = 9.</p>
<p>
<input name="uploadNeed" type="text" id="uploadNeed" maxlength="1">
</p>
<p>
<input type="submit" name="Submit" value="Submit">
</p>
</form>

uploadForm.php

<form name="form1" enctype="multipart/form-data" method="post" action="uploadFiles.php">
<p>
<?
// start of dynamic form
$uploadNeed = $_POST['uploadNeed'];
for($x=0;$x<$uploadNeed;$x++){
?>
<input name="uploadFile<? echo $x;?>" type="file" id="uploadFile<? echo $x;?>">
</p>
<?
// end of for loop
}
?>
<p><input name="uploadNeed" type="hidden" value="<? echo $uploadNeed;?>">
<input type="submit" name="Submit" value="Submit">
</p>
</form>

uploadFiles.php

<?php
$uploadNeed = $_POST['uploadNeed'];
// start for loop
for($x=0;$x<$uploadNeed;$x++){
$file_name = $_FILES['uploadFile'. $x]['name'];
// strip file_name of slashes
$file_name = stripslashes($file_name);
$file_name = str_replace("'","",$file_name);
$copy = copy($_FILES['uploadFile'. $x]['tmp_name'],$file_name);
// check if successfully copied
if($copy){
echo "$file_name | uploaded sucessfully!<br>";
}else{
echo "$file_name | could not be uploaded!<br>";
}
} // end of loop
?>

Copyright © 2008 www.worth2read.org. All rights Reserved. Use of this Site is subject to our Privacy Statement
Untitled Document