View Single Post
Contributor
30May2012,03:07  
Alex.Gabriel's Avatar
Here it is , it should work but since is almost 00.00 i`l go to sleep and i let you test it
Is any error is generated and you can't fix it post it here and somebody or me will fix it.
PHP Code:
<?php
$error_message
="";
$MaxSize "600000";
if (isset(
$_POST['btn_update'])){
function 
createRandomPassword() {
$chars "abcde!@#%^fghijkmnoABCDEFGHIJKpqrstuvwxyz023456789ABCDEFGHIJKLMNOPQRSTUVWZ!@#%^&";
srand((double)microtime()*10000000);
$i 0;
$pass '' ;
while (
$i <= 19) {
$num rand() % 60;
$tmp substr($chars$num1);
$pass $pass $tmp;
$i++;
}
return 
$pass;
}
//checking empty files
if (empty($_FILES) || empty($_FILES['aMyUploads0']) || empty($_FILES['aMyUploads1']) || empty($_FILES['aMyUploads2']))
{
    echo 
'Please select a file to upload';
    exit();
    
//exit if empty file is detected
}
else 
{
if (
$_FILES['aMyUploads0']['size'] > $MaxSize || $_FILES['aMyUploads1']['size'] > $MaxSize || $_FILES['aMyUploads2']['size'] > $MaxSize)
{
$error_message "ERROR: File too big!";
//enable exit if you want to terminate when a file is bigger than Maxsize
//exit(); //added exit since even if filesize is larger than accepted the rest of the code is executed.

}} 
else { 
//if everything is ok


$aMyUploads = array();
$password createRandomPassword();
foreach(
$_FILES as $aFile)
{
//check extension
$allowed_filetypes = array("jpg""gif""jpeg""png");

$ext pathinfo($aFile['name'], PATHINFO_EXTENSION);
if (!
in_array($ext$allowed_filetypes))
{
    echo 
'illegal file type';
    exit();
}
else
{
$upload_directorymkdir("uploads/$password/");
$newLocation $upload_directory.$aFile["name"];
if(
=== $aFile['error'] && (false !== move_uploaded_file($aFile['tmp_name'], $newLocation)))
{
$aMyUploads[] = $newLocation;
}
else
{
$aMyUploads[] = '';
}
}
$error_message="Journal successfully saved.";
$connection mysql_connect("localhost""????""???");
mysql_select_db("????"$connection);
$insert "INSERT INTO photos (image1, image2, image3) VALUES
(
' "
.$aMyUploads[0]." ',
' "
.$aMyUploads[1]." ',
' "
.$aMyUploads[2]." '
)"
;
mysql_query($insert) or die(mysql_error());
}  } }
?>