Example #1
0
echo $usu->email;
echo "</br>";
if (isset($_POST['upload'])) {
    // define the path to the upload folder (DOCUMENT_ROOT er /var/www/adambjorgvins.com/public_html á servernum)
    // destination verður "/var/www/adambjorgvins.com/public_html/upload/images/"
    $server_path_to_upload_folder = $_SERVER['DOCUMENT_ROOT'] . "/upload/images/" . $u->email . "/";
    # Þú þarft að breyta slóð.
    if (!file_exists($server_path_to_upload_folder)) {
        mkdir($server_path_to_upload_folder);
    }
    // svo við getum notað class með t.d. move() fallið og getMessage() ogsfrv...
    require_once 'include/Upload.php';
    // Because the object might throw an exception
    try {
        // búum til upload object til notkunar.  Sendum argument eða slóðina að upload möppunni sem á að geyma skrá
        $loader = new Upload($server_path_to_upload_folder);
        // köllum á og notum move() fallið sem færir skrá í upload möppu, þurfum að gera þetta strax.
        $file_url = "/upload/images/" . $u->email . "/" . $loader->upload();
        // köllum á getMessage til að fá skilaboð (error or not).
        $result = $loader->getMessages();
    } catch (Exception $e) {
        echo $e->getMessage();
        # ef við náum ekki að nota Upload class
    }
}
?>


<!DOCTYPE HTML>
<html>
<head><?php 
Example #2
0
<?php

use File\Upload;
if (isset($_POST['upload'])) {
    echo "<pre>";
    print_r($_FILES);
    echo "</pre>";
    $destination = $_SERVER['DOCUMENT_ROOT'] . "/2T/1608984379/vef_2a/images/";
    require_once 'File/Upload.php';
    // echo $destination;
    try {
        $loader = new Upload($destination);
        $loader->upload();
        $result = $loader->getMessages();
    } catch (Exception $e) {
        echo "<script type='text/javascript'>alert('{$e->getMessage}()')</script>";
    }
}