PHP Getting Media Information From A Remote File - php

So here's the setup. I'm storing and streaming videos on my website. I have a web server where most of the interaction is done and a media server which stores and streams the video files.
I'm trying to write a script on the web server that will list out all of the videos on the media server and get all the information about each video.
I can use the ftp commands through PHP to get the list of files on the media server without any problem. What I am looking to do is also get media information from each remote file such as video duration, codec, bitrate, etc. Not sure if this is possible, but if anyone knew how, it would be someone here on StackOverflow.
Here is the code that I currently have:
$conn = ftp_connect($media_server) or error_out('Failed to connect to FTP server');
ftp_login($conn, $username, $pwd) or error_out('Failed to login to FTP server');
$files = ftp_nlist($conn, ".") or error_out('Could not retrieve list of files');
foreach($files as $file){
$return[] = array('file_name' => $file,
'file_size' => ftp_size($conn, $file));;
}
ftp_close($conn);
echo json_encode($return);
exit();
function error_out($text){
echo '{ "error":"'.$text.'" }';
exit();
}
UPDATE:
I tried the class getID3 at http://getid3.sourceforge.net/ but unfortunately it does not support remote files. The files have to be on the same server.

Related

PHP 5.3 FTP JSON file upload using ftp_put Not uploading

I have a json file where I want to upload it to an ftp account on different server.
I have followed all the code of this function but still I get failed Upload!
here is my code:
$con = ftp_connect('ftp.target-server.com');
$login = ftp_login($con, 'usr', 'pa55');
if (!$con || !$login) {
die('Connection attempt failed!');
}
$destination = 'my-target-file.json';
$source = 'my-source-file.json';
ftp_pasv($con, true) or die("Unable switch to passive mode"); //I have tried this option to force passive mode
$upload = ftp_put($con, $destination, $source, FTP_BINARY); //options: FTP_BINARY|FTP_ASCII and I have tried both
if (!$upload){
echo 'Upload failed!<br><br><br>';
}else{
echo "DONE!";
}
ftp_close($con);
I always get failure although everything seems OK.
N.B.
I have tried the access through filezilla ftp client and I managed to
upload the file manually to target destination.
The source server is using older PHP 5.3 but looks fine regarding the ftp_put function.
Also I have tried my-target-file.txt instead of .json and also failed upload.
I have tried couple of different shared hosting serveres as target server but no luck.
I will be grateful if someone can advise!
I have checked the last error using error_get_last(); and got:Array ( [type] => 2 [message] => ftp_put(): Type set to I [file] => /hermes/......../public/ftp.php [line] => 9 ). I can upload files normally through FTP client filezilla to the target server with the same credentials I am usingbut I can not with ftp_put() as it is not working

Transfer files between two remote FTP servers in PHP

First of all, I know that this a duplicate topic, but the other post that I found were not useful for my situation, so I decided to create a new one.
What I'm trying to accomplish is to get a file from one FTP server and upload it to another FTP server.
I'm using this code:
$ftp_server = "ftp_server";
$ftp_user_name = 'ftp_username' ;
$ftp_user_pass = 'ftp_pass' ;
$localDir = "full/path/";
$serverDir = "full/path/";
$conn_id = ftp_connect($ftp_server);
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
if (ftp_get($conn_id, $localDir, $serverDir, FTP_BINARY)) {
// ftp_fput($conn_id, $file, $fp, FTP_ASCII))
}
The problem that I have is when you use ftp_put command, it requires a local file, but this file it's not on my computer, so I can't upload it to the other ftp.
Is there a way to upload the file that I just got with ftp_get function into another server using ftp_put? Without the need to download it first on your PC?
Thanks!
Both ftp_get and ftp_put can operate with files only, not folders.
Use ftp_get to download a file from the first server to a local temporary folder/file. And then use ftp_put to upload the temporary file to the second server.
If you want to avoid using a temporary file, you can download the file to memory using ftp_fget and re-upload to the second server using ftp_fput.
PHP: How do I read a .txt file from FTP server into a variable?
Transfer in-memory data to FTP server without using intermediate file

How to use FTP to connect to Azure scale set Instance

So i have created a scale set in Azure (2 windows server 2016 VMs). I want to have a PHP application running on them. I want to know if it is possible to use an FTP connection to remotely upload/edit my php files which are going to be on the VMs. If not, what are the others ways i can use to remotely edit/upload my php files?. This is my first time working with a scaleset. thanks
Yes it's possible to use FTP in php:
//open a connection
$conn = ftp_connect($host);
//login to server
ftp_login($conn, $user, $pass);
//upload file
if (ftp_put($conn, $remoteFile, $localFile, FTP_ASCII)) {
return "<p>successfully uploaded $localFile to $remoteFile</p>";
} else {
return "<p>There was a problem while uploading $remoteFile</p>";
}
See the manual for more FTP functions http://php.net/manual/en/book.ftp.php

php big upload via ftp

i have to trasfer file via ftp with php. The files are big (also over 500MB).
So i think use php with ftp.
<?php
// connect and login to FTP server
$ftp_server = "ftp.example.com";
$ftp_conn = ftp_connect($ftp_server) or die("Could not connect to $ftp_server");
$login = ftp_login($ftp_conn, $ftp_username, $ftp_userpass);
$file = "localfile.txt";
// upload file
if (ftp_put($ftp_conn, "serverfile.txt", $file, FTP_ASCII))
{
echo "Successfully uploaded $file.";
}
else
{
echo "Error uploading $file.";
}
// close connection
ftp_close($ftp_conn);
?>
I have to know if the timeout is considered also in ftp trasfer.
If i trasfer the file via php page like upload.php with the code write, i have the execution time limit setting on the web server ?
You must take too many considerations before doing this operation, as mentioned below the first thing you need to check if your FTP server allows 500MB for uploads, the second thing you must set some PHP directives like post_max_size and max_upload_size, I suggest to use an FTP library to make it easier to do that, this a great one php-ftp-client that I've build.
Enable the feature on server side, which allows resuming file uploads.
From php you might be able to call the ftp with command_line options using functions like system(), or exec().
And, yes, in php there are limits: max_upload_size, max_execution_time, max_post_size and etc.
You will have to split the whole process into steps, with reloading of the page - if needed.

How to allow cross-domain file uploads?

I have an html5 uploader thanks to the following tutorial:
http://www.profilepicture.co.uk/ajax-file-upload-xmlhttprequest-level-2/
works great.. however I would like to upload the files to a different domain... I thought this would be possible as long as the domain, or more specifically the file on the domain I was uploading too had the follwong header:
header("Access-Control-Allow-Origin: *")
Therefore allowing cross domain sharing...
However the upload is not working, is there anything else I am missing, or is it a case that you can communicate across domains but you can't upload files?
Kind regards to any responders...
J
I believe the best option for cross domain upload is to use ftp upload (of course you need to know ftp access credential such as ftp host, username and password.
If your using php as server side language you can try this little piece of code.
I use this on multiple domains within the same web server.
$conn_id = ftp_connect($server) or die("<span style='color:#FF0000'>Can't connect to ".$server."</span>");
$login_result = ftp_login($conn_id, $username, $password) or die();
$upload = ftp_put($conn_id, $server_path, $file, FTP_BINARY);
if (!$upload) {
echo "Error sending image to ".$server;
}
Hope this can help you.

Categories