file cretaed using exec could not be accessed immediately after creation?
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="sele开发者_如何学编程ct 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:
}
?>
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.
精彩评论