User Image Uploads

By Simon

So last week I was working on my CMS and it can time to sort out images. Like any good CMS I need to give people the ability to add images to their content. In order to do this I had to use a bit more than some jQuery, so having dabbled with some PHP I decided to go for that.

So I had a little hunt about for some basic tutorials and managed to find one over at dreamweaverclub.com. The code was pretty straight forward.

First of all I had to set up my form:

<form enctype="multipart/form-data" action="uploader.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<input type="file" name="uploadedfile" />
<input type="submit" value="Upload" />
</form>

This form basically posts back to itself and has a standard file input and a hidden 'max file size' input.

Now for the PHP

$target_path = "Images/".$_FILES['uploadedfile']['name']; move_uploaded_file($_FILES['uploadedfile']['tmp_name'],$target_path);

So in the PHP code we set the path of where we want the image to be uploaded to. Then we move the uploaded image and there you have it!

So this is a pretty simple file uploader and is pretty unsecure as it stands, but it has given me the basics of what I need to integrate image uploads into my CMS.

Next week I will be having a bash at getting this working properly so it uploads the image then adds it to the content. Stay tuned.

Related posts