Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Upload videos like Youtube

Posted on 2011-09-10
8
Medium Priority
?
519 Views
Last Modified: 2012-05-12
My customer has to sites: http://admin.sample.com and http://www.sample.com

They use the subdomain: http://admin.sample.com to upload information and images that you can see on http://www.sample.com

With http://admin.sample.com the can upload images and flash galleries, information about their services etc....

My customer ask me that they would like to upload their videos using http://admin.sample.com to publish them in http://www.sample.com, you know something like youtube.

They cannot use youtube because the privacy issues.

So It is possible to do that in their site???

Is there an alternative?????
0
Comment
Question by:altariamx2003
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
8 Comments
 
LVL 21

Expert Comment

by:Papertrip
ID: 36518066
What software is there in the back end that allows them to upload media to http://admin.sample.com ?
0
 

Author Comment

by:altariamx2003
ID: 36518121
Right now I use jquery multifle file to upload images and ckeditor to upload images and flash files

At this moment they cannot upload avi files of mpg files

Is there a way to upload and publish tem???
0
 

Author Comment

by:altariamx2003
ID: 36518135
My first option was the youtube api, but I dont thik that I can use it because the video need to upload it to the youtube website, is that correct????
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 111

Expert Comment

by:Ray Paseur
ID: 36518696
If your servers can handle the load, you can upload the videos directly to the servers and let clients link to them. However you might find that a service like Vimeo is a better solution.
http://vimeo.com/

Privacy issues will probably require a little planning.  You can password-protect any web page and you can keep the videos out of the WWW directory tree, serving them only to authenticated clients.

This little script is a teaching example of how to upload a file or three to your server.  You can install it and run it to see the moving parts.  Insert your own information for the default values shown in the script near the top.  In particular you would want to add to the $file_exts array, and probably raise the $max_file_size value.
<?php // RAY_upload_example.php
error_reporting(E_ALL);


// MANUAL REFERENCE PAGES
// http://php.net/manual/en/features.file-upload.php
// http://php.net/manual/en/features.file-upload.common-pitfalls.php
// http://php.net/manual/en/function.move-uploaded-file.php


// PHP 5.1+  SEE http://php.net/manual/en/function.date-default-timezone-set.php
date_default_timezone_set('America/Chicago');

// ESTABLISH THE NAME OF THE 'uploads' DIRECTORY
$uploads = 'RAY_junk';

// ESTABLISH THE BIGGEST FILE SIZE WE CAN ACCEPT - ABOUT 8 MB
$max_file_size = '8192000';

// ESTABLISH THE MAXIMUM NUMBER OF FILES WE CAN UPLOAD
$nf = 3;

// ESTABLISH THE KINDS OF FILE EXTENSIONS WE CAN ACCEPT
$file_exts = array
( 'jpg'
, 'gif'
, 'png'
, 'txt'
, 'pdf'
)
;

// LIST OF THE ERRORS THAT MAY BE REPORTED IN $_FILES[]["error"] (THERE IS NO #5)
$errors = array
( 0 => "Success!"
, 1 => "The uploaded file exceeds the upload_max_filesize directive in php.ini"
, 2 => "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form"
, 3 => "The uploaded file was only partially uploaded"
, 4 => "No file was uploaded"
, 5 => "UNDEFINED ERROR"
, 6 => "Missing a temporary folder"
, 7 => "Cannot write file to disk"
)
;




// IF THERE IS NOTHING IN $_POST, PUT UP THE FORM FOR INPUT
if (empty($_POST))
{
    ?>
    <h2>Upload <?php echo $nf; ?> file(s)</h2>

    <!--
        SOME THINGS TO NOTE ABOUT THIS FORM...
        ENCTYPE IN THE HTML <FORM> STATEMENT
        MAX_FILE_SIZE MUST PRECEDE THE FILE INPUT FIELD
        INPUT NAME= IN TYPE=FILE DETERMINES THE NAME YOU FIND IN $_FILES ARRAY
        ABSENCE OF ACTION= ATTRIBUTE IN FORM TAG CAUSES POST TO SAME SCRIPT
    -->

    <form name="UploadForm" enctype="multipart/form-data" method="post">
    <input type="hidden" name="MAX_FILE_SIZE" value="<?php echo $max_file_size; ?>" />
    <p>
    Find the file(s) you want to upload and click the "Upload" button below.
    </p>

    <?php // CREATE INPUT STATEMENTS FOR UP TO $n FILE NAMES
    for ($n = 0; $n < $nf; $n++)
    {
        echo "<input name=\"userfile$n\" type=\"file\" size=\"80\" /><br/>\n";
    }
    ?>

    <br/>Check this box <input autocomplete="off" type="checkbox" name="overwrite" /> to <strong>overwrite</strong> existing files.
    <input type="submit" value="Upload" />
    </form>
    <?php
    die();
}
// END OF THE FORM SCRIPT



// WE HAVE GOT SOMETHING IN $_POST - RUN THE ACTION SCRIPT
else
{
    // THERE IS POST DATA - PROCESS IT
    echo "<h2>Results: File Upload</h2>\n";

    // ACTIVATE THIS TO SEE WHAT IS COMING THROUGH
    //    echo "<pre>"; var_dump($_FILES); var_dump($_POST); echo "</pre>\n";

    // ITERATE OVER THE CONTENTS OF $_FILES
    foreach ($_FILES as $my_uploaded_file)
    {
        // SKIP OVER EMPTY SPOTS - NOTHING UPLOADED
        $error_code    = $my_uploaded_file["error"];
        if ($error_code == 4) continue;

        // SYNTHESIZE THE NEW FILE NAME
        $f_type    = trim(strtolower(end    (explode( '.', basename($my_uploaded_file['name'] )))));
        $f_name    = trim(strtolower(current(explode( '.', basename($my_uploaded_file['name'] )))));
        $my_new_file = getcwd() . '/' . $uploads . '/' . $f_name . '.' . $f_type;
        $my_file     =                  $uploads . '/' . $f_name . '.' . $f_type;

        // OPTIONAL TEST FOR ALLOWABLE EXTENSIONS
        if (!in_array($f_type, $file_exts)) die("Sorry, $f_type files not allowed");

        // IF THERE ARE ERRORS
        if ($error_code != 0)
        {
            $error_message = $errors[$error_code];
            die("Sorry, Upload Error Code: $error_code: $error_message");
        }

        // GET THE FILE SIZE
        $file_size = number_format($my_uploaded_file["size"]);

        // IF THE FILE IS NEW (DOES NOT EXIST)
        if (!file_exists($my_new_file))
        {
            // IF THE MOVE FUNCTION WORKED CORRECTLY
            if (move_uploaded_file($my_uploaded_file['tmp_name'], $my_new_file))
            {
                $upload_success = 1;
            }
            // IF THE MOVE FUNCTION FAILED
            else
            {
                $upload_success = -1;
            }
        }

        // IF THE FILE ALREADY EXISTS
        else
        {
            echo "<br/><b><i>$my_file</i></b> already exists.\n";

            // SHOULD WE OVERWRITE THE FILE? IF NOT
            if (empty($_POST["overwrite"]))
            {
                $upload_success = 0;
            }
            // IF WE SHOULD OVERWRITE THE FILE, TRY TO MAKE A BACKUP
            else
            {
                $now    = date('Y-m-d');
                $my_bak = $my_new_file . '.' . $now . '.bak';
                if (!copy($my_new_file, $my_bak))
                {
                    echo "<br/><strong>Attempted Backup Failed!</strong>\n";
                }
                if (move_uploaded_file($my_uploaded_file['tmp_name'], $my_new_file))
                {
                    $upload_success = 2;
                }
                else
                {
                    $upload_success = -1;
                }
            }
        }

        // REPORT OUR SUCCESS OR FAILURE
        if ($upload_success == 2) { echo "<br/>It has been overwritten.\n"; }
        if ($upload_success == 1) { echo "<br/><strong>$my_file</strong> has been saved.\n"; }
        if ($upload_success == 0) { echo "<br/><strong>It was NOT overwritten.</strong>\n"; }
        if ($upload_success < 0)  { echo "<br/><strong>ERROR: $my_file NOT SAVED - SEE WARNING FROM move_uploaded_file() COMMAND</strong>\n"; }
        if ($upload_success > 0)
        {
            echo "$file_size bytes uploaded.\n";
            if (!chmod ($my_new_file, 0755))
            {
                echo "<br/>chmod(0755) FAILED: fileperms() = ";
                echo substr(sprintf('%o', fileperms($my_new_file)), -4);
            }
            echo "<br/><a href=\"$my_file\">See the file $my_file</a>\n";
        }
    // END FOREACH ITERATOR - EACH ITERATION PROCESSES ONE FILE
    }
}

Open in new window

0
 
LVL 7

Expert Comment

by:boon86
ID: 36518830
there is many tube site on sales at the market with ready function and everything, my favorite is:

http://www.clip-share.com
and
http://www.adultvideoscript.com <-- adult site like redtube, youporn, ( of course you can use it as non adult site )

hope that help
0
 

Author Comment

by:altariamx2003
ID: 36520280
Thanks for your answers

One of the files that they can upload at this time are flv files.

I made a little script to organize thouse file in a multimedia galleries.

I was thinking about this post, what happend if I convert there avi and mpg files to flv ( just like youtube)

And after the conversion I use my script???

I that possible???????

is there a script or something like that????????????

PD Sorry for my english
0
 
LVL 7

Accepted Solution

by:
boon86 earned 2000 total points
ID: 36520994
You will need to :

1. convert your video files to flv
2. metainject your video files using flvtool2 or yamdi , so that you able to play it with player like jwplayer, flowplayer

to convert to flv:

        $cmd            = '/usr/local/bin/mencoder /path/to/your/video.mpg -o /path/to/you/output/video.flv -ovc x264 -x264encopts profile=baseline:bitrate=140:nocabac:vbv_maxrate=1500:vbv_bufsize=2000:level_idc=30:global_header:frameref=2:mixed_refs:me=umh:no8x8dct:subq=6:partitions=all:threads=auto:bframes=0 -af resample=44100:0:0,volnorm=1:0.25 -oac faac -faacopts mpeg=4:object=2:raw:br=128 -of lavf -lavfopts format=mp4 -ofps 24.000 -vf harddup 2>&1';        
 
exec($cmd. ' 2>&1', $output);

Open in new window


for metainjection i used yamdi:

$cmd = '/usr/bin/yamdi -i /path/to/you/output/video.flv -o /path/to/you/metainjected/output/video.flv 2>&1';
exec($cmd. ' 2>&1', $output);

Open in new window


other useful function for thumb and get video duration:

function get_video_duration($video_path, $video_id)
{
    global $config;
    $cmd = $config['mplayer']. ' -quiet -nolirc -vo null -ao null -frames 0 -identify "' .$video_path. '"';
    log_conversion($config['LOG_DIR']. '/' .$video_id. '.log', $cmd);
    exec($cmd, $output);
    log_conversion($config['LOG_DIR']. '/' .$video_id. '.log', implode("\n", $output));
    while ( list($k,$v) = each($output) ) {
        if ( $length = strstr($v, 'ID_LENGTH=') ) {
            break;
        }
    }
    
    if ( isset($length) ) {
        $lx = explode('=', $length);
        
        return $lx['1'];
    }
    
    return '0';
}

function extract_video_thumbs($video_path, $video_id)
{
    global $config;
    
    $duration   = get_video_duration($video_path, $video_id);
    if ( $duration > 180 ) {
        $ss     = 60;
        $step   = 5;
    } elseif ( $duration > 120 ) {
        $ss     = 15;
        $step   = 5;
    } elseif ( $duration > 60 ) {
        $ss     = 10;
        $step   = 2;
    } else {
        $ss     = 1;
        $step   = 1;
    }
    
    $i = 0;
    mkdir($config['TMP_DIR']. '/thumbs/' .$video_id);
    mkdir($config['TMB_DIR']. '/' .$video_id);
    while($i <= 20 ) {
		$width  = $config['img_max_width'];
		$height = $config['img_max_height'];
		if ($i == 0) {
			$width  = 320;
			$height = 240;
		}
	
        if ( $config['thumbs_tool'] == 'ffmpeg' ) {
            $cmd    = $config['ffmpeg']. ' -i ' .$video_path. ' -f image2 -ss ' .$ss. ' -s ' .$width. 'x' .$height. ' -vframes 2 -y ' .$config['TMP_DIR']. '/thumbs/' .$video_id. '/%08d.jpg';
        } else {
            $cmd    = $config['mplayer']. ' ' .$video_path. ' -ss ' .$ss. ' -nosound -vop scale='.$width.':'.$height.' -vo jpeg:outdir=' .$config['TMP_DIR']. '/thumbs/' .$video_id. ' -frames 2';
        }
        
        log_conversion($config['LOG_DIR']. '/' .$video_id. '.log', $cmd);
        exec($cmd. ' 2>&1', $output);
        log_conversion($config['LOG_DIR']. '/' .$video_id. '.log', implode("\n", $output));
        
        if ( file_exists($config['TMP_DIR']. '/thumbs/' .$video_id. '/00000002.jpg') ) {
            $src    = $config['TMP_DIR']. '/thumbs/' .$video_id. '/00000002.jpg';
        } else {
            $src    = $config['TMP_DIR']. '/thumbs/' .$video_id. '/00000001.jpg';
        }
        $dst    = ( $i == 0 ) ? $config['TMB_DIR']. '/' .$video_id. '/default.jpg' : $config['TMB_DIR']. '/' .$video_id. '/' .$i. '.jpg';
        log_conversion($config['LOG_DIR']. '/' .$video_id. '.log', $src. "\n" .$dst);
        copy($src, $dst);
        
        $ss = $ss+$step;
        if ( $ss > $duration ) {
            $ss = $ss-$step;
        }
        
        ++$i;
    }
    @unlink($config['TMP_DIR']. '/thumbs/' .$video_id);
}

Open in new window


Hope that help
0
 

Author Closing Comment

by:altariamx2003
ID: 36812940
let me try it
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Browsers only know CSS so your awesome SASS code needs to be translated into normal CSS. Here I'll try to explain what you should aim for in order to take full advantage of SASS.
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
The viewer will receive an overview of the basics of CSS showing inline styles. In the head tags set up your style tags: (CODE) Reference the nav tag and set your properties.: (CODE) Set the reference for the UL element and styles for it to ensu…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question