Location: PHPKode > scripts > Php AddressBook 2 > php-addressbook-2/upload-file.php
<?
// you can change this to any directory you want
// as long as php can write to it
$uploadDir = 'profiles/';

    $fileName = $_FILES['profile']['name'];
    $tmpName  = $_FILES['profile']['tmp_name'];
    $fileSize = $_FILES['profile']['size'];
    $fileType = $_FILES['profile']['type'];

    // get the file extension first
    $ext      = substr(strrchr($fileName, "."), 1); 
    
    // generate the random file name
    $randName = md5(rand() * time());
    
    // and now we have the unique file name for the upload file
    $filePath = $uploadDir . $randName . '.' . $ext;

    // move the files to the specified directory
    // if the upload directory is not writable or
    // something else went wrong $result will be false
    $result    = move_uploaded_file($tmpName, $filePath);
    if (!$result) {
        echo "Error uploading file";
        exit;
    }
       
    if(!get_magic_quotes_gpc())
    {
        $fileName  = addslashes($fileName);
        $filePath  = addslashes($filePath);
    }  
    
//    echo "<br>File uploaded<br>";       
?>
Return current item: Php AddressBook 2