2017 © Pedro Peláez
 

yii2-extension yii2-remote-uploaded-file

image

nik-zp/yii2-remote-uploaded-file

  • Saturday, May 20, 2017
  • by nik-zp
  • Repository
  • 1 Watchers
  • 0 Stars
  • 15 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 50 % Grown

The README.md

Yii2 remote uploaded file

Upload file to remote server, (*1)

Install

The preferred way to install this extension is through composer., (*2)

To install, run, (*3)

$ php composer.phar require nik-zp/yii2-remote-uploaded-file "dev-master"

or add, (*4)

"nik-zp/yii2-remote-uploaded-file": "@dev"

to the require section of your composer.json file., (*5)

Usage (for example)

use nikzp\uploadedFile\UploadedFile;
...
$file = UploadedFile::getInstanceByName('file');
$file->saveAs('http://img.example.com/catalog/user/56/image.jpg');

POST: to img.example.com server with image, (*6)

Image Server

.htaccess, (*7)

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_METHOD} POST
RewriteRule ^(.*) upload.php?image=$1 [L]

upload.php, (*8)

<?php
if (!empty($_FILES['file']['tmp_name']) && !empty($_GET['image'])) {
    $to = './'.$_GET['image'];
    $dir = pathinfo($to,PATHINFO_DIRNAME);
    if(!is_dir($dir)) {
        mkdir($dir, 0755, true);
    }
    if (move_uploaded_file($_FILES['file']['tmp_name'], $to)) {
        echo json_encode(['success'=>true]);
    } else {
        echo json_encode(['success'=>false]);
    }
}
return;

The Versions

20/05 2017

dev-master

9999999-dev

  Sources   Download

MIT

by Nikolai Paschenko