0
  • i have a .php file from a videohoster who says that this code is a comandline code which allows me to upload a video to their site and i need to create an interface for a random user that he can upload a video to the videohoster while staying on my website. i thought i simple form like below in html is enought but apparently it doesent work:

front-end, html:

<h2>This form allows you to upload a Video.</h2>
<form action="uploadapi.php" method="post" enctype="multipart/form-data"><br>
  <p>Video Name: <input type="text" name="titel" size="50" /></p>
  <p>Video Description:<br/><textarea name="text" rows="5" cols="50">    </textarea></p>
  <p>Select File, allowed: .mpg </br><input type="file" name="file"></p>
  <p><input type="submit" value="Upload"</p>
 </form>

the uploadapi.php is supplied by the hoster and so i assume it is correct.

<?php

////////////////////////////////////////////////////////
// for php 5.6+ you need to make some changes in code
// method 1
// add the following line
// curl_setopt($ch, CURLOPT_SAFE_UPLOAD, 0);
//
// method 2
// change 
// $post_fields['vfile'] = "@".$file;
// to
// $post_fields['vfile'] = CURLFile($file);
////////////////////////////////////////////////////////

$apiversion = "2.123.20150426";

//REQUIRED Registered Users - You can find your user token in API page.
$user_token = "xxx";


if(count($argv) < 2)
die("Usage: php $argv[0] [VIDEO TO UPLOAD] {SUB FILE}\n");

$file = $argv[1];
if(!file_exists("$file"))
die("ERROR: Can't find '$file'!\n");

$path_parts = pathinfo($file);
$ext = $path_parts['extension'];

$allowed = array("mov");

if (!in_array(strtolower($ext),$allowed))
die("ERROR: Video format not permitted. Formats allowed: .mov!\n");

if(isset($argv[2]))
{
$sub_file = $argv[2];

if(!file_exists("$sub_file"))
die("ERROR: Can't find '$file'!\n");

$path_parts = pathinfo($sub_file);
$ext = $path_parts['extension'];

$allowed = array("srt");

if (!in_array(strtolower($ext),$allowed))
die("ERROR: Subtitle format not permitted. Formats allowed: .srt!\n");

$post_fields['subfile'] = "@".$sub_file;
}

$converter = file_get_contents("http://.../getconv_uploadapi.php?   upload_hash=".$user_token);

if($converter=="ERROR")
die("ERROR: Could not choose converter. Aborting... \n");

$post_fields['vfile'] = CURLFile($file);
$post_fields['upload'] = "1";
$post_fields ['token'] = 'xxx';
if(!empty($user_token))
$post_fields['upload_hash'] = $user_token;

$ch = curl_init(); 
curl_setopt($ch, CURLOPT_URL,$converter); 
curl_setopt($ch, CURLOPT_POST,1); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $post_fields); 
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec ($ch); 
curl_close ($ch);

echo "$result\n";
?>

is my methodology correct (using html form to call the uploadapi.php on my server) or do i need in order to sumit my video to the videohoster via uploadapi.php other programming languages (ajax, javascript etc)?

2
  • narrowed the question down Commented Jul 13, 2015 at 14:13
  • which part are you stuck on? try to condence your question to an area you are having issues with, currently we dont know if the php you've added works, doesnt work or what's wrong with it Commented Jul 13, 2015 at 14:15

2 Answers 2

1

Provided file is command-line file. It means it won't work on web as expected. For example, on web you won't have $argv[1] or $argv[2].

You have two options:

  • you can rewrite uploadapi.php considering that source file is a file that came from your form
  • or upload your file and call uploadapi.php as a command-line script with arguments using shell_exec or exec, for example.
Sign up to request clarification or add additional context in comments.

Comments

0

i thought that i define or fill the variable $argv[1] from the html form since: type="file" name="file">

= $file = $argv[1];?

... ok rewriting upload api is no alternative since it comes from the hoster.

so what i need to do is uploading the uploadapi.php on my server and then keeping my html form like it is? and insted of action=uploadapi.php i need a action=somethingsomething.php which has an exec command to execute uploadapi.php?:

<?php
function somethingsomething($uploadapi) {
exec($uploadapi . " > /dev/null &");  
}
?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.