Click here to Skip to main content
15,893,564 members
Articles / Web Development

PHP SimpleSix Uploader

Rate me:
Please Sign up or sign in to vote.
4.60/5 (9 votes)
9 Apr 2012CPOL 17.6K   520   8  
A simple file uploader written in PHP.
<?

	$file = $_FILES['file'];
	$name = $_POST['name'];
	$path = $_POST['path'];
	$upload = $_POST['upload'];
	
	if(isset($upload)){
		
		if($file['name']){
			
			if($name){
				
				if(strlen($path) > 5){
					
					move_uploaded_file($file['tmp_name'], $path.$name);
					
					echo "<font color=green>File successfully uploaded!</font>";
				
				} else 
					echo "<li> Please enter the path!";
			
			} else 
				echo "<li> Please put the file name!"; 
		
		} else 
			echo "<li> No file to upload";
			
		echo "<br /><hr />";
	}

?><table width="100%" border="0" cellspacing="0" cellpadding="0">
  <form method="post" enctype="multipart/form-data">
    <tr>
    <td height="40" colspan="2"><h2><strong>Uploader</strong></h2></td>
  </tr>
  <tr>
    <td height="25">File:</td>
    <td><label>
      <input name="file" type="file" id="file" size="35">
    </label></td>
  </tr>
  <tr>
    <td width="1%" height="25" nowrap>Re-name file:&nbsp;</td>
    <td><label>
      <input type="text" name="name" id="name">
      <em>(ex.filename.txt)</em></label></td>
  </tr>
  <tr>
    <td height="25" bgcolor="#FAFAFA">Path to:</td>
    <td bgcolor="#FAFAFA"><label>
      <input name="path" type="text" id="path" size="30">
      <em>(ex. folder/dir/.../)</em></label></td>
  </tr>
  <tr>
    <td height="25">&nbsp;</td>
    <td><label>
      <input type="submit" name="upload" id="upload" value="Up..">
    </label></td>
  </tr>
  <tr>
    <td height="10" colspan="2">&nbsp;</td>
    </tr>
  <tr>
    <td height="10" colspan="2"><em>Uploader path: <?= getcwd(); ?></em></td>
  </tr>
  </form>
</table>
<p>Author: <strong>Agon Avdimetaj</strong></p>

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
CEO Graphsix Studio
Albania Albania
CEO / Web & App Developer @ Graphsix Studio.
Studying Computer Engineering @ Faculty of Electrical and Computer Engineering, UP.

Comments and Discussions