/*
* a super simple uploader to catch incoming images
* Michael Sharon 2006
*
* creates a file called test.log
* use the command - tail -f test.log to watch the file for debugging purposes
*
* For more information on PHP file uploads - read this http://us3.php.net/features.file-upload
*
*/
log2file("something happened... ");
$path = "/home/msharon/uberthings.com/mobile/tmp/";
print "hi there mobile app design kids!!
";
//if you want to log the entire contents of the POST and FILES arrays - uncomment these
//log2file($_POST);
//log2file($_FILES);
if (isset($_POST['name'])){
print "got the name - ".$_POST['name']."
";
log2file("got the name - ".$_POST['name']);
//if there is a temporary file
if (isset($_FILES['photo']['tmp_name'])) {
//grab the original file name
$name = $_FILES['photo']['name'];
//get the name of the temp file we uploaded it to
$tmp_name = $_FILES['photo']['tmp_name'];
log2file("Received file - $name, tmp name = $tmp_name
");
print("Received file - $name, tmp name = $tmp_name
");
$newpath = $path;
$temp = explode(".", $name);
$extension = strtolower($temp[1]);
$newfile = $path.$name;
print "newfile = $newfile
";
//url of where we'll be saving it
$url = 'http://uberthings.com/mobile/tmp/'.$name;
//this is all for directory creation - remove if you don't need it
if (is_dir($newpath)) {
log2file("$newpath exists");
} else {
if (mkdir($newpath, 0775)) {
log2file("$newpath directory created");
} else {
log2file("$newpath dir creation failed");
}
}
if (move_uploaded_file($tmp_name, $newfile)) {
log2file("File was uploaded to $newfile");
print('| File was uploaded to '.$newfile.' - '.$url.'
');
} else {
log2file("File does not exist or there was an error");
print("| File does not exist or there was an error");
}
}
}
else
{
//the following section will be shown if you just go to the URL with a normal web browser
?>