Пример #1
0
         // use named placeholders
         $sql = 'INSERT INTO images (filename, caption)
                 VALUES (:filename, :caption)';
         $stmt = $conn->prepare($sql);
         $stmt->bindParam(':filename', $names[0], PDO::PARAM_STR);
         $stmt->bindParam(':caption', $_POST['caption'], PDO::PARAM_STR);
         $stmt->execute();
         // use rowCount() to get the number of affected rows
         $imageOK = $stmt->rowCount();
     }
     // get the image's primary key or find out what went wrong
     if ($imageOK) {
         // lastInsertId() must be called on the PDO connection object
         $image_id = $conn->lastInsertId();
     } else {
         $imageError = implode(' ', $loader->getMessages());
     }
 } elseif (isset($_POST['image_id']) && !empty($_POST['image_id'])) {
     // get the primary key of a previously uploaded image
     $image_id = $_POST['image_id'];
 }
 // don't insert blog details if the image failed to upload
 if (!isset($imageError)) {
     // create SQL
     $sql = 'INSERT INTO blog (image_id, title, article)
             VALUES(:image_id, :title, :article)';
     // prepare the statement
     $stmt = $conn->prepare($sql);
     // bind the parameters
     // if $image_id exists, use it
     if (isset($image_id)) {
Пример #2
0
<?php

use PhpSolutions\File\Upload;
// set the maximum upload size in bytes
$max = 51200;
if (isset($_POST['upload'])) {
    // define the path to the upload folder
    $destination = 'C:/upload_test/';
    require_once '../PhpSolutions/File/Upload.php';
    try {
        $loader = new Upload($destination);
        $loader->upload();
        $result = $loader->getMessages();
    } catch (Exception $e) {
        echo $e->getMessage();
    }
}
?>
<!DOCTYPE HTML>
<html>
<head>
    <meta  charset="utf-8">
    <title>Upload File</title>
</head>

<body>
<?php 
if (isset($result)) {
    echo '<ul>';
    foreach ($result as $message) {
        echo "<li>{$message}</li>";
Пример #3
0
*/
// set the maximum upload size in bytes
use PhpSolutions\File\Upload;
// set the maximum upload size in bytes
$max = 60000 * 1024;
// 60 MB
if (isset($_FILES['uploadFile'])) {
    // define the path to the upload folder
    $destinationFile = 'uploads/file/';
    try {
        $loaderFile = new Upload($destinationFile, 'uploadFile');
        $loaderFile->setMaxSize($max);
        $loaderFile->allowAllTypes();
        $loaderFile->upload();
        $uploadFile1 = $loaderFile->getName();
        $resultFile = $loaderFile->getMessages();
        $_SESSION['uploadFile'] = $uploadFile1;
    } catch (Exception $e) {
        echo $e->getMessage();
    }
    if (!empty($uploadFile1)) {
        $uploadsFile = $destinationFile . $uploadFile1;
    } else {
        $uploadsFile = "";
    }
}
/*if (isset($_FILES['uploadBill'])) {
    // define the path to the upload folder
    $destinationBill = 'uploads/bill/';
    try {
        $loaderBill = new Upload($destinationBill, 'uploadBill');