Hi Dudes.
I had an uploader but I’ve decided, after reading this article…
http://www.scanit.be/uploads/php-file-upload.pdf
That it needs to be more secure. So I’ve disabled it.
The article goes into some quite complex details about what code to use. I have difficulty following it in such a way that I could end up producing working code. But I’ve been able to pick up enough to have an idea of what I need to do for an uploader…
Firstly, I want the files to be accessable from a URL directly. So my plan is that I will have personal control over the files that end up in the directory in question.
Secondly, I want people to be able to upload files without my direct supervision. So I want an uploader to do three four things…
Upload the file with a randomized file name to a folder outside the public html folder.
Add a record to a table called something like ‘pending_moderation’ which has the real filename, and the randomized filename.
Limit the filenames to ‘.jpg’ or ‘.jpeg’ (or possibly also ‘.gif’ if it is as secure as the first two) and the mime types to the same.
sanitize the data input.
The latter presents a problem with file uploading - It doesn’t work well with filenames. It has problems with the slashes and the dots. This would be a nightmare with the local filename as there could be any number of subdirs.
In the hope of illustrating my point. This…
<?php
$filename = "c: hepictures\apicture.jpg";
$con = mysql_connect();
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db();
$sanitized = mysql_real_escape_string($filename);
echo $sanitized;
?>
outputs this…
“c: hepictures\apicture.jpg”
the ’ ’ at has been removed.
It seems like any picture or folder that begins with a slash command will be broken.
Any advice on all this? Should I not even be attempting this if my php abilities aren’t up to that level?