tags:

views:

19

answers:

1

HI

I'm using exec in php to execute a command and it will create a .png file in a temp folder..

After creating that i'm trying to open that file and read contents and process them,,

but i end up file could not read error..

I think the time taken by the exec to execute and create a file is the cause for the issue..

but i dont know how to fix it? i tried sleep() but it makes my script to run slow

<?php
    error_reporting(E_ALL);
    extension_loaded('ffmpeg') or die('Error in loading ffmpeg');
        //db connection codes
    $max_width  = 120;
    $max_height = 72;
    $path ="/path/";
    $qry="select id, input_file, output_file from videos where thumbnail='' or thumbnail is null;";
    $res=mysql_query($qry);
    $cnt = 1; 
    while($row = mysql_fetch_array($res,MYSQL_ASSOC))
    {
        $outfile  = $row[output_file];
        $imgname  = $cnt.".png";
        $srcfile  = "/path/".$outfile;

        echo "####$srcfile####";
        exec("ffmpeg -i ".$srcfile." -r 1 -ss 00:00:05 -f image2 -s 120x72 ".$path.$imgname);
        $nname = "./temp/".$imgname;
        echo "nname===== $nname";
        $fileo = fopen($nname,"rb");
        if($fileo)
        {
        $imgData = addslashes(file_get_contents($nname));
                ..
                ...
                ....
        }
        else
            echo "Could not open<br><br>"; // this stmt is printed while executing
        $cnt = $cnt + 1:
    }
?>
A: 

You are creating a file at $path.$imgname, and then you are trying to read "./temp/$imgname" which I would assume are 2 totally different files.

webdestroya
i replaced the original path with the name 'path' while posting , that's all. I'm sure the path are correct and the files are created with proper permissions which i checked with filezilla.
kvijayhari
Why dont you do `echo $path.$imgfile."==./temp/".$imgname;` and see if they actually are the same?
webdestroya
I checked it and the files are same...
kvijayhari