rubing Posted November 23, 2008 Share Posted November 23, 2008 My php code seems to be executing prematurely. I am trying to download a file and then delete it if it is too small as follows: //this just tells curl to save a file ($file) and print info about the transfer $grab->get_file($url,$conn,$proxy); if (filesize($file)>60000) { echo "file was too small"; unlink($file); } Now, the file i am downloading is big enough and curl reports that back to me, but php is detecting as too small and deleting it: Array ( => http://www.stinkyrhthm.com/colors.mp3 [content_type] => audio/mpeg [http_code] => 206 [header_size] => 777 [request_size] => 1226 [filetime] => -1 [ssl_verify_result] => 0 [redirect_count] => 1 [total_time] => 177.030566 [namelookup_time] => 0.168462 [connect_time] => 0.193816 [pretransfer_time] => 0.193823 [size_upload] => 0 [size_download] => 3000001 [speed_download] => 16946 [speed_upload] => 0 [download_content_length] => 3000001 [upload_content_length] => 0 [starttransfer_time] => 0.283526 [redirect_time] => 2.976578 ) file was too small Why do I think this is b/c php is prematurely executing my code???? Glad you asked! If I change filesize to a smaller number e.g. 30,000 then it will work! Maybe this is a bug ??? //this just tells curl to save a file ($file) and print info about the transfer $grab->get_file($url,$conn,$proxy); if (filesize($file)>30000) { echo "file was too small"; unlink($file); } Quote Link to comment https://forums.phpfreaks.com/topic/133939-premature-code-execution/ Share on other sites More sharing options...
GingerRobot Posted November 23, 2008 Share Posted November 23, 2008 Where is this array of information coming from? Are you sure the unit used for size_download is bytes? Edit: That didn't make much sense - ignore. Quote Link to comment https://forums.phpfreaks.com/topic/133939-premature-code-execution/#findComment-697238 Share on other sites More sharing options...
sasa Posted November 23, 2008 Share Posted November 23, 2008 change if (filesize($file)>60000) to if (filesize($file)<60000) Quote Link to comment https://forums.phpfreaks.com/topic/133939-premature-code-execution/#findComment-697239 Share on other sites More sharing options...
rubing Posted November 23, 2008 Author Share Posted November 23, 2008 oooops, that was dumb of me! Quote Link to comment https://forums.phpfreaks.com/topic/133939-premature-code-execution/#findComment-697259 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.