Online File Storage with PHP

In this tutorial, I will show you how easy it is to create an online file storage system with PHP. You will learn how to upload files with PHP and list them by scanning the “uploads” folder.

Introduction

Have you ever wished that you had a place to upload files while on the road? What if you’re using a public terminal or someone else’s computer and cannot install any third party software for file transfer?
Wouldn’t it be neat to just open a page in a browser, and upload your file with the click of a button?

There’s plenty of file hosting sites already all around, but in this tutorial I will show you how to make your own. Here’s what we will be creating:

Step 1 – Basic HTML

Let’s get started. The first thing we need is an empty HTML document. I use XHTML 1.0 Transitional with ISO-8859-1 char set. If you prefer, and don’t have any need for special characters, you can replace this with UTF-8 char set.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Online file storage</title>
</head>
<body>

</body>
</html>

Step 2 – Adding the File Upload Form

Ok, now that we have a basic HTML file, we have basically nothing :) So let’s add some content. I’ll wrap all the contents in a DIV element to help style the page with CSS. The Fieldset and Legend tags are perhaps somewhat rare, but they are the definite markup for organizing content into groups.

I’ve added a password field that we’ll be using to shoo away unwanted uploaders, as we don’t want strangers to fill up our file quota with random junk.

Note that in contrast to the standard everyday Form element, this one has the enctype set to multipart/form-data.
This is needed for POSTing files and must be here. I’ve set the action modifier to point to this very same file.
What that means is that once the form is submitted, the form data will be POSTed back to the same page.

The hidden MAX_FILE_SIZE field is for PHP and defines the maximum size (in bytes) that we can submit. This however won’t override the MAX_FILE_SIZE setting in the php.ini file, so that will always be the one that determines the max size.

<div id="container">
	<h1>Online File Storage</h1>

	<fieldset>
		<legend>Add a new file to the storage</legend>
		<form method="post" action="index.php" enctype="multipart/form-data">
		<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
		<p><label for="name">Select file</label><br />
		<input type="file" name="file" /></p>
		<p><label for="password">Password for upload</label><br />
		<input type="password" name="password" /></p>
		<p><input type="submit" name="submit" value="Start upload" /></p>
		</form>
	</fieldset>
</div>

If we open the file in a browser, now we will have a boring and plain html form. It will submit content to itself but won’t know what to do with it.

We need a place to display the files that we’ve already uploaded; so add the following html inside the container div under the first fieldset.

<fieldset>
	<legend>Previousely uploaded files</legend>
	<ul id="menu">
		<li><a href="">All files</a></li>
		<li><a href="">Documents</a></li>
		<li><a href="">Images</a></li>
		<li><a href="">Applications</a></li>
	</ul>

	<ul id="files">
	</ul>
</fieldset>

Notice that the unordered list with the id “files” is empty. Don’t worry about that right now as we will fill that section with the files in the server.

Step 3 – Add CSS and JS

I used jQuery to create the ability to toggle the visibility of certain file types without having to refresh the page.
This is purely optional and removing the JS will speed up the loading of the page somewhat. So let’s add the following lines to the HEAD of the HTML file.

<style type="text/css" media="all">
	@import url("style/style.css");
</style>
<script src="http://code.jquery.com/jquery-latest.js"></script>

I’m loading the jQuery from an external source at runtime. Again if you prefer, you can change this so that the file is loaded from a local source with this line.

<script type="text/javascript" src="js/jquery-1.3.2.min.js"></script>

Loading the file directly from code.jquery.com ensures that we are using the latest version and saves our bandwidth on every page load, but if the code.jquery.com server would happen to be down or overcrowded, we might not get the file when we need it.

Create a new folder called style and create a new CSS file in it with the name style.css. This will be the file that tells the browser how we want the page to look. There’s quite a lot of CSS here, but it’s simple enough for anyone to follow.

Now the page should look something like the following.

@CHARSET "ISO-8859-1";

body
{
	background-color: #cddcec;
	font-family: "Arial";
	font-size: 11px;
}

div#container
{
	width: 600px;
	margin: 0px auto;
	border: 1px solid #e6eef6;
	background-color: #ffffff;
}

div#container h1
{
	background-color: #4b75b3;
	margin: 0px;
	padding: 8px;
	font-family: "Arial";
	font-weight: normal;
	border: 1px solid #3564a9;
}

div#container fieldset
{
	margin: 20px;
	border: 1px solid #98b9d0;
}

ul#menu
{
	list-style-type: none;
	margin: 4px;
	padding: 0px;
}

ul#menu li
{
	float: left;
	margin: 4px;
}

ul#menu li.active
{
	background-color: #98b9d0;
	border-left: 1px solid #3564a9;
	border-top: 1px solid #3564a9;
	border-bottom: 1px solid #e6eef6;
	border-right: 1px solid #e6eef6;
}

ul#menu li a
{
	text-decoration: none;
	font-size: 10px;
	padding: 2px;
	color: #3564a9;
}

ul#files
{
	list-style-type: none;
	margin: 40px 0px 0px 0px;
	padding: 0px;
}

ul#files li
{
	background-color: #fff7c0;
	border-bottom: 1px solid #efefef;
	padding: 2px;
	margin-bottom: 1px;
}

What we should now have is illustrated in the following image.

Step 4 – Handling File Input Submissions with PHP

Let’s start the PHP side of the tutorial by creating a Settings class. In this class we can save the upload password as well as the file path for the uploads folder.
We can then include the class into our page and use it’s values when needed.
You can write PHP files with pretty much the same tools you use to write HTML and CSS, just remember to save the file with the .php suffix.

<?php
/**
 * Class Settings holds the upload settings
 *
 */
class Settings
{
	static $password = "mypassword";
	static $uploadFolder = "uploads/";
}
?>

Without going any deeper into Object Oriented Programming (OOP), what the code does is it creates a new class with the kind of values that can be accessed without instantiating the class.
We can now access it’s values simply by calling Settings::$password; and Settings::$uploadFolder; This is also the place where you can change the password whenever you please.
The <?php and ?> mark the beginning and the end of a PHP code segment. These segments can be written inside normal html pages and the server will interpret them when the page is requested.

Ok, now we get to business. In the html file we’ve been working with, let’s add the following into the very top of the file. Yes, before the <head> tag.

<?php
//Load the settings
require_once("settings.php");

$message = "";

First we tell the PHP interpreter to include our settings file. I’ve also set up a new variable $message. Later on I shall write process information into this variable and display it to the user.

//Has the user uploaded something?
if(isset($_FILES['file']))
{

If the form has been submitted with a file, the $_FILE array should have a value with the key we used as the name of the file input field.

	$target_path = Settings::$uploadFolder;
	$target_path = $target_path . time() . '_' . basename( $_FILES['file']['name']);

Here we get the path to the upload folder we specified in the settings. On line 2, we add (concatenate) the name of the uploaded file into the target path.
Note also that I’ve added the current server timestamp into the beginning of the filename. There are two reasons for me doing this.
First it is used to store the date and second it will make sure that all files are of different names.
Should we be using a database behind this application, the time of adding would be there, and we could serialize the filenames and save the original name only in the database table,
but as there’s no database, we can just use this workaround.

	//Check the password to verify legal upload
	if($_POST['password'] != Settings::$password)
	{
		$message = "Invalid Password!";
	}
	else
	{

If the submission was made without giving any password or if the given password was something other than the one defined in the settings, we won’t handle the file and only return a message indicating a false password.

		//Try to move the uploaded file into the designated folder
		if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {
		    $message = "The file ".  basename( $_FILES['file']['name']).
		    " has been uploaded";
		} else{
		    $message = "There was an error uploading the file, please try again!";
		}
	}
}

Ok, so the password was right, now what? Now we “save” the file. I say save in parenthesis since the file is actually already in the server; it’s just in the temporary folder.
So to make the file accessible and to make sure the server won’t delete it when the temp is cleared, we must move it to some safe location. I’ve used the move_uploaded_file function.
The function takes two arguments. First is the temporary name of the file assigned automatically by the server, and the other is the target path we assigned earlier.
The function returns a Boolean value indicating an successful operation. Again we set the message value to inform the user what happened.

if(strlen($message) > 0)
{
	$message = '<p class="error">' . $message . '</p>';
}

And that’s how easy it is to upload files to server with PHP! Here I’ve just checked whether anything has been written into the message variable (length more that 0) and format it so we can style it with CSS.

Step 5 – List the Uploaded Files

/** LIST UPLOADED FILES **/
$uploaded_files = "";

//Open directory for reading
$dh = opendir(Settings::$uploadFolder);

The first thing to do is to create a folder handle. All it takes is one command. The variable uploaded_files is where we’ll be writing the folder filenames in HTML format.

//LOOP through the files
while (($file = readdir($dh)) !== false)
{

Here we loop through the files in the folder. As long as we can read the next file in the folder into the file variable we do so and move on. Once we’ve gone through all the files, the function return false and ends the loop.

	if($file != '.' && $file != '..')
	{

The ‘.’ and ‘..’ are also returned by this function so we’ll have to make sure we don’t attempt to do anything with those.

		$filename = Settings::$uploadFolder . $file;
		$parts = explode("_", $file);

We add the name of the file into the path of the uploads folder and save it as filename variable. Then we explode the name of the file at the ‘_’ character.
This function returns an array of strings splitting the original string every time there’s a ‘_’.
Since there’s one of those characters, we’ll receive an array with the timestamp part as cell 1 and the original file name as cell 2.

		$size = formatBytes(filesize($filename));
		$added = date("m/d/Y", $parts[0]);
		$origName = $parts[1];

Now that we have the timestamp value as it’s own string, we can format it into a date and save the original filename as it’s own variable.
The filesize function provided by PHP returns the size of the file in bytes only, so we’ll format it into a more readable form with the formatBytes function, which is covered in a bit.

		$filetype = getFileType(substr($file, strlen($file) - 3));
        $uploaded_files .= "<li class=\"$filetype\"><a href=\"$filename\">$origName</a> $size - $added</li>\n";

When uploading a file into the server, PHP provides us with the file type information, but since we have no place to store that information, we’ll have to try to get the file type with a custom function.
I’m giving the three last chars of the file name as a parameter to the getFileType function (shown later on). I’m using the filetype variable to style the different files with CSS.
All that’s left now is to generate an HTML string and add it into the uploaded_files variable and close the folder handle.

	}
}
closedir($dh);
if(strlen($uploaded_files) == 0)
{
	$uploaded_files = "<li><em>No files found</em></li>";
}

If no files were found, set the uploaded_files var to display a message.

We also have to show the uploaded_files string somewhere; so add this line inside the <ul> with the id ‘files’.

<?php echo $uploaded_files; ?>

Step 6 – Auxiliary Function

The getFileType function tries to guess what type the file is by reading the last chars of it’s name. This won’t work with extensions like .jpeg and .tiff.
To make it more universal, we’d have to read a substring starting at the period and going to the end of the file name.
But then if the name is something like my.new.car.pic we’d get new.car.pic as the extensions.
So to make this really work we would have to find the last period in the name and take a substring from there on.
But for the scope of this tutorial this is close enough.

function getFileType($extension)
{
	$images = array('jpg', 'gif', 'png', 'bmp');
	$docs 	= array('txt', 'rtf', 'doc');
	$apps 	= array('zip', 'rar', 'exe');

	if(in_array($extension, $images)) return "Images";
	if(in_array($extension, $docs)) return "Documents";
	if(in_array($extension, $apps)) return "Applications";
	return "";
}

This next function formats the bytes into a more readable format. Just basic math — nothing more. The function itself is from the PHP.net function comments.

function formatBytes($bytes, $precision = 2) {
    $units = array('B', 'KB', 'MB', 'GB', 'TB'); 

    $bytes = max($bytes, 0);
    $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
    $pow = min($pow, count($units) - 1); 

    $bytes /= pow(1024, $pow); 

    return round($bytes, $precision) . ' ' . $units[$pow];
}
?>

And that’s it for the PHP part. Just some more JS and CSS and we’re all done.

Step 7 – A Touch of CSS for Increased Readability

What we have this far should look like:

But to make good use of the getFileType function and the class name it returns, I’ve added the next lines of CSS into the style.css file.

ul#files li a
{
	text-decoration: none;
	color: #3564a9;
	padding: 2px 25px;
	background-position: left;
	background-repeat: no-repeat;
}

ul#files li.Documents a
{
	background-image: url('../images/text.jpg');
}

ul#files li.Images a
{
	background-image: url('../images/picture.jpg');
}

ul#files li.Applications a
{
	background-image: url('../images/zip.jpg');
}

p.error
{
	background-color: #fff7c0;
	border-bottom: 1px solid #efefef;
	font-weight: bold;
	color: #ff0000;
	padding: 6px;
}

I’m assigning an icon to each type of file. The icon’s I’ve used are from the magnificent collection found at http://www.famfamfam.com.
Now what we should have is something like this.

Ah, much better.

Step 8 – Toggle File Visibility with jQuery

For a finishing bit, let’s add some extra functionality with JavaScript. Create a new folder called “js” and in that folder make a new file, filestorage.js.
Then add the following line to end of the HTML page right before the </body> tag.

<script src="js/filestorage.js" />

It’s considered a good practice to include these kind of js files at the very end of the page to allow the Document Object Model (DOM) to load first.

function HideFiles(selector)
{
	//show all files
	if(selector === "All files")
	{
		$("#files > li").show();
		return true;
	}
	else
	{
		//show only the selected filetype
		$("#files > li").hide();
		$("#files > li." + selector).show();
		return true;
	}
}

The HideFiles function does two things. If the parameter selector is equal to ‘All files’, the function goes through all the <li> -items inside the files <ul> and makes them visible.
If, however, some other parameter was given, the function hides everything and then shows only the ones with the same class name as the parameter.

function prepareMenu()
{
	$("#menu li").click(
		function () {
			$("#menu li").each(
				function(){
					$(this).removeClass("active");
				}
			);
			$(this).addClass("active");
			HideFiles($(this).children().html());
	    return false;
	});

	//Select the first as default
	$("#menu li:first").click();
}

The prepareMenu function adds a function to the onClick event on the menu <li>s.
Upon a click, remove the class ‘active’ from all of them and then add it to the one that was clicked and call the HideFiles function with the text inside the element inside the clicked <li>.
Finally, we invoke the onClick event on the first menu element to make sure it’s selected as default when the page loads.

$(document).ready(function()
{
	prepareMenu();
});

Don’t forget to call the prepareMenu function when the page is loaded. This can be done easily by calling it inside the document’s ready event as shown above.
Now the menu “buttons” should be working and upon clicking them the list of files should change.

Step 9 – Congratulate Yourself for a Job Well Done!

That’s it! You should now have a working online file storage.
Just remember to create a “uploadFolder,” and change its CHMOD to allow for modification. Instructions for this can be found all around the web and directly from your hosting provider.

This has been a tutorial for the beginners. Hopefully it was in depth enough without being TOO explanatory.

Thank you for reading and please leave a comment if you have any questions.


Related Posts

Add Comment

Discussion 73 Comments

  1. nice to see posts from Computer Scientists .
    good tut.

  2. jasmin says:

    nice tutorial ……..

  3. MG-7 says:

    Nice one Thank you man

  4. B says:

    great way to do this without using a database. A demo would be nice.

  5. Shannon says:

    Is there an easy way to switch the upload directory, based on the password used? It would be great to use this with multiple people, each with their own upload directory. Great tutorial!

  6. Zy says:

    Hm… not bad.
    It is a good introduction and few basics on how the file storage and file uploading works.

  7. Jash Sayani says:

    Here is online file storage with CodeIgnitor framework: http://CloudDisk.co.cc

  8. Chris says:

    I realize this is a beginner’s tutorial, but it may be in your interest to warn beginners not to deploy this in a live environment. It has quite a few security vulnerabilities, including being able to execute scripts on the server.

  9. Jermaine Hercules says:

    Nice work Antti I was wonder how to do this

  10. Theres no error checking or validation. Basic tutorial at best, I wouldnt recommend it really.

    I wrote a file uploader with robust validation and even anti-virus scanning, but its for CakePHP.

    Take a gander: http://www.milesj.me/resources/script/uploader-plugin

  11. Mike says:

    This is a great tutorial. Lately we’ve been having problems with some clients sending files to us. Sometimes they don’t have a FTP client to upload files. When everyone had IE6, it was easy to tell them how to connect to a ftp server using the browser and drag files to upload. With IE7, the method is different and doesn’t work half the time.

    I’m going to give this a shot. In a future tutorial, you could expand on this one…maybe add a progress bar for large files or something.

    • Web010 says:

      That can be done with a jquery plugin. Enter “jquery ajax upload progress bar” in google search and you will find few of them.

      PS It’s not really ajax upload, it uses hidden iframes. Ajax upload is not possible.

  12. this is im waiting now i can use this to my site! cheers! many thanks.

  13. Dasani says:

    Well done! This is what I am going to use to resolve some problems! I didn’t even think about this :)

  14. Jacki says:

    Nice!

    What is your favorite way to show upload progress? PHP APC plugin, Flash, Perl?

  15. I’m curious, what keeps some Korean hacker from uploading executable PHP or other code?

  16. Aayush says:

    This is amazing…I mean I know how to make it….but it’s just soo great to have another code for reference…

  17. Hanne says:

    As a PHP novice, and reading these comments, could people pointing out the flaws please list them? It would be nice to know what you think the writer should have done better, allow for more insight and better learning for us trying to learn PHP :)

    • alex says:

      .php files can be dangerous, they can wipe out an entire database system, corrupt your data, or extract data, which puts privacy policies at risk etc.

      Allowing them to be uploaded, and executed puts your server at risk.

      And also, .bat files have the ability to wipe out entire hard drives whcih i doubt a server hosting company will be too happy about..

      Simple enough to get around,

      Allow uploads of any types except dangerous ones, (like those)

      $fileType = $_file['type'];

      if($fileType = .php || .bat) {
      echo “You are not allowed to upload this type of file”;
      }else{
      // upload script
      }

  18. Julio Zebadua says:

    i think you must make a tutorial of use of ftp because i find a many tutorial about but they are all berry confused maybe you can make a better one thnks

  19. William Rouse says:

    When I test this on my local machine, my files have a prefix with numbers, for example “1247701490_American Political.doc”, when I uploaded the file”American Political.doc”.
    Thanks!

    • William Rouse says:

      Forgot about the time stamp.

    • Developnew says:

      I think timestamp use for remove duplication problem.
      example
      1247701490_myPhoto.gif
      1247701491_myPhoto.gif

      I am just thinking not sure…

      • Dave Kennedy says:

        It can prevent duplication, however it can also help preventing the fiile being executed via a browser.

        If I upload “hacksite.php”… then all I have to do is go to url http://www.example.com/uploads/hacksite.php.

        Changing the name helps prevent this attack in the most basic of forms (timestamps are not a good idea), salting and hashing would be better, however the simplest solution is to upload them to an inaccessible directory e.g outside the root.

  20. Filip Benes says:

    I think it would be better to use timestamp as sufix for better organisation in folder …

    myPhoto_12702900009.gif

    and code will be something like this
    $image_info = pathinfo($_FILES['file']['name']);
    $target_path = $target_path.$image_info['filename'].”_”.time().”.”.$img_info["extension"]);

  21. razz says:

    Why have you used objects instead of constants (in the class)? Moreover the rest of the code is written in procedural style. I think you could use simply define() function. :-) But nice tutorial, thanks. I’m sorry for my English…

  22. hash says:

    “The getFileType function tries to guess what type the file is by reading the last chars of it’s name. This won’t work with extensions like .jpeg and .tiff. To make it more universal, we’d have to read a substring starting at the period and going to the end of the file name. But then if the name is something like my.new.car.pic we’d get new.car.pic as the extensions. So to make this really work we would have to find the last period in the name and take a substring from there on. But for the scope of this tutorial this is close enough.”

    I can’t help wondering if you haven’t copy pasted some of this code. You’re dong a Masters degree in computer science, but didn’t think there could be an easy way to get the location of the last period in a string, and then grab the extension from there? Or is using some pretty basic php methods “beyond the scope”.

    $ext = substr($name, strrstr($name, ‘.’)+1);

  23. Zach Alig says:

    Gah!! Needed this a week ago for a project! Great stuff. I’ll use it in the future.

  24. Robert says:

    So really… am I the only one who is looking at the use of @import for the stylesheet going ‘huh’? Why not just use a link if all you’re going to do is hard-code an import…

    • Steven says:

      One reason one might apply CSS to a document using this method would be to hide the CSS from older browsers and small screened mobile devices that have limited or no support for CSS and do not support the @import rule. This will insure that your webpages look good no matter who is viewing them and with what.

  25. dwainehead says:

    I would recomend using ezfilemanager instead, http://www.webnaz.net/ezfilemanager/
    easy to intergrate to your existing secured member or admin area as well works great as a tinymce plugin, the best rule to remeber is DO NOT Trust user input! validate!

  26. zzz says:

    this site is gay

  27. revive says:

    As a PHP novice, and more of a front-end design guy trying to learn some PHP to better communicate with our development team.. can someone shed some light on the vulnerabilities of this script.. I understand sanitation and validation, but how would that be implemented in this script.. maybe this is another tutorial in itself.. but if anyone with the knowledge would like to share, I know myself and some others would like to learn..

    • David Ironside says:

      As Dave Kennedy writes above…

      “If I upload “hacksite.php”… then all I have to do is go to url http://www.example.com/uploads/hacksite.php.

      hacksite.php may contain damaging code, say for example it deletes all of the files on the server up to the root. For this code to be executed, (assuming in this example one figures out the timestamp associated with the upload), then all you need do is visit the file via a web browser.

      Secondly privacy is an issue here. Again uploading private-bank-details.doc using this code can be viewed (in the simplest form without the timestamp) via http://www.example.com/uploads/private-bank-details.doc.

      • Paul Chater says:

        Why would anybody want to upload a file called “Private-bank-details.doc” though? I’m sure nobody on this planet are actually dumb enough to upload their private bank details for public viewing on a server. :/

      • Antti Sand says:

        As stated before, you can’t simply type in /hacksite.php ‘cose the filename is changed on upload. Furthermore, due to the password field only you should be able to upload stuff to the server so if you want to run the hacksite.php it’s not the job of this code to stop you. Why not just upload the hacksite.php to the server with simple ftp? I just don’t get this nonsense about uploading harmful code using your own upload form.

        Notice also that in the tutorial there’s only set a password for uploading files, and not for downloading. This is because the point of this tutorial is not to make a safe place for online files – for that I would recommend cryptography – but to show some file handling techniques for beginners. The application show in the tutorial is by all means NOT supposed to be ready-to-ship product, but something to help follow the steps.

        I accept all critique, but, seriously, this is a tutorial for beginners. There’s plenty to be said about securing online applications, but that was not the subject of this tutorial, as I think I mentioned in the text.

    • Kevin Jensen says:

      A simple example would be a simple file:

      <?php

      print file_get_contents( $_GET['file'] );

      ?>

      Once the file is uploaded click on it in under the “Current files” and you’ll get some errors. Add ?file=../index.php to the end of your URI (http://localhost/uploads/1248329298_hack.php?file=../index.php) and then view the source. Simple files like this make it easy for someone to read your PHP code and pick out the good stuff like your password (http://localhost/uploads/1248329298_hack.php?file=../settings.php).

      • Antti Sand says:

        But to able to upload the hack.php you must already know the password so what exactly do you gain? It’s indeed pretty simple to hack into somewhere if you already have the password :D

  28. Steven says:

    Just one small problem. On step 8 you used the script tag as if it was a self closing tag.

    It should be like this.

    Had me confused for a little while. Easy mistake. Great tutorial!

  29. sunjester says:

    there was no filtering. can we say owned? if this guy is a computer scientist, send him back to school.

    • Antti Sand says:

      Your attitude amazes me. Is it not obvious to you that the application is meant as a sample and even as such it’s usage is limited to the owner of the site, so why on earth would we need filtering? You’re free to upload to your server whatever you like as you are with an ftp client. If the form was public so that anyone could upload whatever they like, THEN it would need filtering.

      And yes, I’m still in school.

  30. Brian says:

    Hey guys,

    I cant seem to find where I specify my FTP address?

    Please can someone point me in the right direction here… Everyone seems to be working fine with this… I can only see a password option but not the FTP server settings itself??

  31. LOVER says:

    Its Working but..

    Is there any way to show the HTML code of the file after it is uploaded…

  32. B Jones says:

    Hi,

    Great tutorial for a beginner like myself. Gives me a good understanding of various things.

    However it doesn’t work.

    This is the error I get:
    Parse error: parse error, expecting `’(” in /home/sites/v/a/l/*****.net/www/file_storage/index.php on line 11

    What would be doing this?

    The line of code on line 11 is:
    $target_path = Settings::$uploadFolder;

    Thanks for putting the effort in to this tutorial. It has been beneficial for me.

  33. barten says:

    I am trying to build a CMS as a casestudy and to learn. I want to build a
    “media-gallery”. It is important to me that it is secure and multiple people can use it – so in the future i can actually use it.
    Anyone have a suggestion for a tutorial for that? or a premade application/script?

  34. barten says:

    ..and thanks for a great tuorial i enjoyed it very much : )

  35. Ciprian says:

    Awsome tutorial.Thanks

  36. kevin says:

    great stuff.
    i get error
    Warning: date() expects parameter 2 to be long, string given in C:\www\index.php on line 51

    $target_path = $target_path . time() . ‘_’ . basename( $_FILES['file']['name']);
    #$target_path = $target_path . basename( $_FILES['file']['name']) . ‘_’ . time();

    when i try to change file name

  37. SkipSoft says:

    How can I filter extension?

  38. KIRAN says:

    Why do i keep getting errors… why?

    Warning: move_uploaded_file(/labs/uploads/1252250193_2.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/[REMOVED FOR PRIVACY/labs/index.php on line 20

    Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move ‘/tmp/php7LtZyO’ to ‘/labs/uploads/1252250193_2.jpg’ in /home/[REMOVED FOR PRIVACY/labs/index.php on line 20

    Warning: opendir(/labs/uploads/) [function.opendir]: failed to open dir: No such file or directory in /home/[REMOVED FOR PRIVACY] on line 41

    Warning: readdir(): supplied argument is not a valid Directory resource in /home/[REMOVED FOR PRIVACY]/labs/index.php on line 44

    Warning: closedir(): supplied argument is not a valid Directory resource in /home/[REMOVED FOR PRIVACY/labs/index.php on line 57

  39. Harish Chouhan says:

    Hi, Great tutorial. It takes serious time to create a tutorial and explain things to others. Thanks again as it cleared my basics and gave me ideas to work on…

  40. thearchitect says:

    I am having a problem getting this to work on my Mac. I am using MAMP on Leopard and I keep getting a “file not uploaded error”. I check my php config file and File uploads is enabled with a 32MB limit.

  41. Dione says:

    Great tutorial for a beginner like myself!

    I think this is a good initial application on which interested PHP beginners can build upon and learn from.

    Harsh comments need not be said I believe :-)

    Peace!

  42. RoXs says:

    Very well done, thank you for sharing your expertise =)
    Thanks
    Your RoXs.

  43. Elegendz says:

    Its a great TUTORIAL for PHP Practice.

  44. sudin says:

    Hello,

    Seems a very useful tutorial. I’ve faced a problem..

    When I use opendir() function it gives an erro msg like this

    [function.opendir]: failed to open dir: not implemented

    Can you help me???

    Regards,
    Sudinem

Add a Comment