php: $ HTTP_POST_FILES eşdeğer yüklemek?

2 Cevap

Ben bir API için bir dosya göndermek zorunda. API documentation bir dosya yükleme komut ($ _FILES) aracılığıyla bu nasıl bir örnek sağlar. Ama aynı makinede dosyaları var, bu nedenle bu adımı atlayın ve sadece zaman kazanmak için doğrudan dosya okumak istiyorum.

Bu kod parçası ile çalışacak şekilde nasıl dosyası (video) okuyabilirsiniz?

Ben sadece gerçekten o veri parçası (I fread kullanırım bu kod ile çalışmak için aynı biçimde okumak gerekir, ben DOSYALAR bir dizi olduğunu anlıyorum, ama ayrı ayrı bunun diğer bölümlerini (dosya) ayarlayabilirsiniz? içeriğini almak Dosya?)

<?php

# Include & Instantiate
require('../echove.php');
$bc = new Echove(
    'z9Jp-c3-KhWc4fqNf1JWz6SkLDlbO0m8UAwOjDBUSt0.',
    'z9Jp-c3-KhWdkasdf74kaisaDaIK7239skaoKWUAwOjDBUSt0..'
);

# Create new metadata
$metaData = array(
    'name' => $_POST['title'],
    'shortDescription' => $_POST['shortDescription']
);

# Rename the video file
$file = $_FILES['video'];
rename($file['tmp_name'], '/tmp/' . $file['name']);
$file_location = '/tmp/' . $file['name'];

# Send video to Brightcove
$id = $bc->createVideo($file_location, $metaData);

>

Herhangi bir yardım için şimdiden teşekkür ederiz!

2 Cevap

Er - yapmanız gereken istediğiniz tüm hayır, konumu, bir dosya tanıtıcısı ya da bir şey beslemek mi?

$files = $_FILES['video'];
$filename = $files['name'];
$file_location = '/home/username/' . $filename; // maybe append the extension
$id = $bc->createVideo($file_location, $metaData);

Ya da daha basitçe

$id = $bc->createVideo( '/foo/bar/baz.txt', $metaData );

Eğer yerel diskinizde dosyasına noktası dışındaki herhangi bir şey yapmanıza gerek yok gibi görünüyor. Ne hakkında:

<?php

# Include & Instantiate
require('../echove.php');
$bc = new Echove(
    'z9Jp-c3-KhWc4fqNf1JWz6SkLDlbO0m8UAwOjDBUSt0.',
    'z9Jp-c3-KhWdkasdf74kaisaDaIK7239skaoKWUAwOjDBUSt0..'
);

# Create new metadata
$metaData = array(
    'name' => $_POST['title'],
    'shortDescription' => $_POST['shortDescription']
);

# point at some file already on disk
$file_location = '/path/to/my/file.dat'; // <== if the file is already on the box, just set $file_location with the pathname and bob's yer uncle 

# Send video to Brightcove
$id = $bc->createVideo($file_location, $metaData);