file cretaed using exec could not be accessed immediately after creation?

Posted by Holicreature on Stack Overflow See other posts from Stack Overflow or by Holicreature
Published on 2010-05-17T05:14:27Z Indexed on 2010/05/17 5:20 UTC
Read the original article Hit count: 233

Filed under:
|
|

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>";
        $cnt = $cnt + 1:
    }
?>

© Stack Overflow or respective owner

Related posts about php

Related posts about exec