help with php, I'm confused here

User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: help with php, I'm confused here

Post by Neo » Thu Apr 22, 2010 2:17 am

Regarding your file size issue....
It seems that the system isn't returning the exact file size as the file is opened exclusively by the encoder. I'm sure you are able to get the size of a normal file?

Try to call following function (dos_filesize) instead of 'filesize' function.

Code: Select all

<?php
// outputs e.g.  somefile.txt: 1024 bytes
function dos_filesize($fn) {

    if (is_file($fn))
        return exec('FOR %A IN ("'.$fn.'") DO @ECHO %~zA');
    else
        return '0';
}

$filename = 'somefile.txt';
echo $filename . ': ' . dos_filesize($filename) . ' bytes';
?>
 

Regarding multiple extensions issue....
You may replace the following code and test. What I do is, I simply extract the file extension and use that. (I assume you only have video files in that directory as previously mentioned).

Code: Select all

            if ( is_file($dir.$file) ){

                   $ext = substr($file, strrpos($file, '.'));
             
                   $sub_file = str_ireplace($ext, ".srt", $dir.$file);
                   $idx_file = str_ireplace($ext, ".idx", $dir.$file);
                   $thumb_file = str_ireplace($ext, ".jpg", $dir.$file);
                   $out_file = str_ireplace($ext, ".drc", $dir.$file);
                   flv_convert_get_thumb($dir.$file, $sub_file, $idx_file, $thumb_file, $out_file);
                }
                else{
                    continue;
                }
            }
 
Mysoogal
Captain
Captain
Posts: 223
Joined: Thu Dec 17, 2009 7:15 am
Location: Planet VPS

Re: help with php, I'm confused here

Post by Mysoogal » Thu Apr 22, 2010 3:00 am

sorry i think i confused you here, :D

you see this code, it works

code A

Code: Select all

<?php

// outputs e.g.  somefile.txt: 1024 bytes

$filename = 'somefile.txt';
echo $filename . ': ' . filesize($filename) . ' bytes';

?> 
now my problem is adding this code into this script below

code B

Code: Select all

<?

//define the path as relative
$path = "../files";
 

//using the opendir function
$dir_handle = @opendir($path) or die("Unable to open $path");

echo " ";

while ($file = readdir($dir_handle)) 
{
   if($file!="$file.avi" && $file!="$file.srt")

if($file!="." && $file!="..")

if($file != "encode_to_mkv.php" && $file != "encode_to_theora.php") 
if($file != "encode_to_mpeg2.php") 
if($file != "encode_to_svcd.php")
if($file != "encode_to_thumbsnailer.php")
if($file != "encode_to_wmv.php")
if($file != "encode_to_dirac.php")
if($file != "encode_to_xvid.php")
if($file != "divx2pass.log")
if($file != "encode_to_dvd.php")
if($file != "encode_to_dv.php")
if($file != "encode_to_psp.php")
if($file != "progress.php")
if($file != "remote_uploader.php")
if($file != "downloader.php")
if($file != "script.inc.php")
if($file != "sst.php")
 

 


      echo "$file</a><br/>";
}


//closing the directory
closedir($dir_handle);

?> 

when i try to add

Code: Select all

 $filename . ': ' . filesize($filename) . ' bytes'  
into into code B

so it should also report the filesize in Mb

like this

Code: Select all

echo "$file . ': ' . filesize($file) . ' </a><br/>";  

thats about it, i have completed the remote upload system :mrgreen:

Image
Mysoogal
Captain
Captain
Posts: 223
Joined: Thu Dec 17, 2009 7:15 am
Location: Planet VPS

Re: help with php, I'm confused here

Post by Mysoogal » Thu Apr 22, 2010 3:04 am

Regarding multiple extensions issue....
the problem here is not about the extensions but, how to add more input types

for example right now the video encoding script only accepts avi as input right, im trying to figure how to add more input types, such as mkv ,wmv,flv etc, i know i can just make new profiles for each example avi to mkv, or mkv to avi etc but that will really make it more complicated.
Mysoogal
Captain
Captain
Posts: 223
Joined: Thu Dec 17, 2009 7:15 am
Location: Planet VPS

Re: help with php, I'm confused here

Post by Mysoogal » Thu Apr 22, 2010 4:01 am

I've just finished adding file management script nearly completed, just that file size issue needs to be addressed then its going public yahoo !

i will post it on ubuntu forum, it should be to easy to change the windows ffmpeg usage into Linux usage thus script becomes compatible on Linux server ,

this script would be most used by seed-box users, with the management script everything seems complete. thanks goodness now how just to figure that file size

Image
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: help with php, I'm confused here

Post by Neo » Thu Apr 22, 2010 2:27 pm

Bit of quote confusion I think. Try following code.

Code: Select all

echo $file . ': ' . filesize($file) . '</a><br/>';  
Mysoogal
Captain
Captain
Posts: 223
Joined: Thu Dec 17, 2009 7:15 am
Location: Planet VPS

Re: help with php, I'm confused here

Post by Mysoogal » Fri Apr 23, 2010 12:10 am

Neo wrote:Bit of quote confusion I think. Try following code.

Code: Select all

echo $file . ': ' . filesize($file) . '</a><br/>';  
error

Code: Select all


Warning: filesize() [function.filesize]: stat failed for Possessed.II.(1984).DVDRip.XviD-MDCOrient.avi in D:serverxampphtdocsstatusprogressive.php on line 38
Possessed.II.(1984).DVDRip.XviD-MDCOrient.avi:

Warning: filesize() [function.filesize]: stat failed for Possessed.II.(1984).DVDRip.XviD-MDCOrient.srt in D:serverxampphtdocsstatusprogressive.php on line 38
Possessed.II.(1984).DVDRip.XviD-MDCOrient.srt: 
 

the code I'm using

Code: Select all

<?

//define the path as relative
$path = "../files";
 

//using the opendir function
$dir_handle = @opendir($path) or die("Unable to open $path");

echo " ";

while ($file = readdir($dir_handle)) 
{
   if($file!="$file.avi" && $file!="$file.srt")

if($file!="." && $file!="..")

if($file != "encode_to_mkv.php" && $file != "encode_to_theora.php") 
if($file != "encode_to_mpeg2.php") 
if($file != "encode_to_svcd.php")
if($file != "encode_to_thumbsnailer.php")
if($file != "encode_to_wmv.php")
if($file != "encode_to_xvid.php")
if($file != "divx2pass.log")
if($file != "encode_to_dvd.php")
if($file != "encode_to_dv.php")
if($file != "progress.php")
if($file != "remote_uploader.php")
if($file != "downloader.php")
if($file != "script.inc.php")
if($file != "sst.php")
if($file != "ft2.php")
 

 


     echo $file . ': ' . filesize($file) . '</a><br/>';
}


//closing the directory
closedir($dir_handle);

?> 
why did somebody have to invent filesize if its not working :evil: php developers i want to hang :mrgreen:
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: help with php, I'm confused here

Post by Neo » Fri Apr 23, 2010 5:40 am

Mysoogal wrote:
Regarding multiple extensions issue....
the problem here is not about the extensions but, how to add more input types

for example right now the video encoding script only accepts avi as input right, im trying to figure how to add more input types, such as mkv ,wmv,flv etc, i know i can just make new profiles for each example avi to mkv, or mkv to avi etc but that will really make it more complicated.
Sure. I understand that. My earlier code was about getting extension using strpos. But I have seen you are using . everywhere on the file name. So please use the following function to get the extension.

Code: Select all

$ext = substr(strrchr($file, '.'), 0);  
Using this, you will get srt, idx, jpg and drc accordingly for each file.
Say you need to encode a wmv file for example, so the $ext would be .wmv

You can get the extension without dot as below.

Code: Select all

$ext = substr(strrchr($file, '.'), 1);  
This will return you wmv

Mostly the encoder applications knows to detect the source type. You'll only have to define the destination type.
However, if yours is required, then you can pass wmv as you need.

If you not clear, pls ask.
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: help with php, I'm confused here

Post by Neo » Fri Apr 23, 2010 6:03 am

For the size issue, still the path is missing to the file, isn't it?
Try following code.

Code: Select all

echo $file . ': ' . filesize($path."/".$file) . '</a><br/>'; 

Also, you can remove checking the php files as below with $ext.

Code: Select all

//using the opendir function
$dir_handle = @opendir($path) or die("Unable to open $path");

echo " ";

while ($file = readdir($dir_handle)) 
{
    $ext = substr(strrchr($file, '.'), 1);

   if($file != "$file.avi" && $file != "$file.srt" && $file != "." && $file != ".." && $ext != "php"){
      echo $file . ': ' . filesize($path."/".$file) . '</a><br/>';
   }
} 
Keep me informed about progress.
Mysoogal
Captain
Captain
Posts: 223
Joined: Thu Dec 17, 2009 7:15 am
Location: Planet VPS

Re: help with php, I'm confused here

Post by Mysoogal » Sat Apr 24, 2010 12:52 am

thanks neo very much after reading so much about filesize i still do not understand it completely :roll: but i got it working without changing the entire code i just used the echo part you changed, it seems it needed to have the $file path inserted there also i think :D neo how to convert bytes to Mb ? :?: I'm reading here http://php.net/manual/en/function.filesize.php

how can i use this code with mine so it reports encoding in Mb instead of bytes

Code: Select all

<?php

function formatBytes($bytes, $precision = 2) {
    $units = array('B', 'KB', 'MB', 'GB', 'TB');
  
    $bytes = max($bytes, 0);
    $pow = floor(($bytes ? log($bytes) : 0) / log(1024));
    $pow = min($pow, count($units) - 1);
  
    $bytes /= pow(1024, $pow);
  
    return round($bytes, $precision) . ' ' . $units[$pow];
}
?>

its porting bytes so working :D

Code: Select all


<?

//define the path as relative
$path = "../files";

//using the opendir function
$dir_handle = @opendir($path) or die("Unable to open $path");

echo " ";

while ($file = readdir($dir_handle)) 
{
   
if($file!="$file.avi" && $file!="$file.srt")
if($file!="." && $file!="..")
if($file != "encode_to_mkv.php" && $file != "encode_to_theora.php") 
if($file != "encode_to_mpeg2.php") 
if($file != "encode_to_svcd.php")
if($file != "encode_to_thumbsnailer.php")
if($file != "encode_to_wmv.php")
if($file != "encode_to_xvid.php")
if($file != "divx2pass.log")
if($file != "encode_to_dvd.php")
if($file != "encode_to_dv.php")
if($file != "progress.php")
if($file != "ft2.php")

 



     echo $file . ': ' . filesize($path."/".$file) . ' </a><br/>';
}




//closing the directory
closedir($dir_handle);

?> 


?> 
reporting size in bytes. :geek:
Image
Mysoogal
Captain
Captain
Posts: 223
Joined: Thu Dec 17, 2009 7:15 am
Location: Planet VPS

Re: help with php, I'm confused here

Post by Mysoogal » Sat Apr 24, 2010 1:01 am

neo about the
$ext = substr(strrchr($file, '.'), 0);
post you made i don't understand it :roll:

what do you mean ?

for example, just to make things clear, i'm using this script which only supports avi, container

Code: Select all


    $dir = './'; // set to current folder
    if ($handle = opendir($dir)) {
        while(false!== ($file = readdir($handle))) {

            if ( is_file($dir.$file) ){
                if (preg_match("'\.(avi)$'", $file) ){
                   $sub_file = str_ireplace(".avi", ".srt", $dir.$file);
                   $idx_file = str_ireplace(".avi", ".idx", $dir.$file);
                   $thumb_file = str_ireplace(".avi", ".jpg", $dir.$file);
                   $out_file = str_ireplace(".avi", ".dv", $dir.$file);
                   flv_convert_get_thumb($dir.$file, $sub_file, $idx_file, $thumb_file, $out_file);
                }
                else{
                    continue;
                }
            }
        }
        closedir($handle);
    }


    
    function flv_convert_get_thumb($in, $in_sub, $in_idx, $out_thumb, $out_vid){
        
        $cmd = 'D:\server\encoder\ffmpeg.exe -i '.$in.' -target ntsc-dv '.$out_vid.'';
        $res = shell_exec($cmd);
    }

 
so your saying if this addded

Code: Select all

$ext = substr(strrchr($file, '.'), 0);  
i do not need this part

Code: Select all

if (preg_match("'\.(avi)$'", $file)
:?:

i dont get it sorry :cry:
Post Reply

Return to “PHP & MySQL”