whit3fir3 Posted December 3, 2009 Share Posted December 3, 2009 I have a function that uses cURL to download images and writes them to a file. After the file is written I call fclose() on my file that I was writing to as well as curl_close() on the cURL object. I want to get the size of the file by calling filesize(); When I do this it returns the value of FALSE. The only thing that I can figure is that cURL still has some kind of lock on the file. Can anyone thing of a way to clear to clear the lock and or a different way to get the size of the file? Thanks, whit3fir3 Quote Link to comment https://forums.phpfreaks.com/topic/183915-problem-with-curl-filesize/ Share on other sites More sharing options...
PFMaBiSmAd Posted December 3, 2009 Share Posted December 3, 2009 Any chance you are checking if the file exists first and that cached status is being returned later in your code? See this note from the filesize() section of the manual - Note: The results of this function are cached. See clearstatcache() for more details. Quote Link to comment https://forums.phpfreaks.com/topic/183915-problem-with-curl-filesize/#findComment-970893 Share on other sites More sharing options...
whit3fir3 Posted December 4, 2009 Author Share Posted December 4, 2009 Thank you for your quick response, but the clearstatcache() did not fix the problem. You were correct though, I am checking to see if the file_exists() earlier in the code. Any example of the code I am using is below. I have tried clearstatcache() both with no parameters and with passing it the optional parameters of the file I want it to clear the stat cache for. $file = fopen($localPath, 'a'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$imgURL); curl_setopt($ch, CURLOPT_USERAGENT, $agent); curl_setopt($ch, CURLOPT_FILE,$file); curl_setopt($ch, CURLOPT_HEADER, 0); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); curl_setopt(ch, CURLOPT_TIMEOUT, 20); curl_exec($ch); curl_close($ch); fclose($file); clearstatcache(); $sizeOfFile = filesize($file); Quote Link to comment https://forums.phpfreaks.com/topic/183915-problem-with-curl-filesize/#findComment-970905 Share on other sites More sharing options...
salathe Posted December 4, 2009 Share Posted December 4, 2009 The filesize function expects it's parameter to be a string containing the path to the file. In your script $file is a resource, not a string. Perhaps you instead want $sizeOfFile = filesize($localPath); You could also get the information from cURL to see how big the downloaded file is. Quote Link to comment https://forums.phpfreaks.com/topic/183915-problem-with-curl-filesize/#findComment-970921 Share on other sites More sharing options...
whit3fir3 Posted December 4, 2009 Author Share Posted December 4, 2009 Wow...I am not sure sure how I missed that, but you were correct salathe that solved the problem. Thank you for pointing out my mistake there. Quote Link to comment https://forums.phpfreaks.com/topic/183915-problem-with-curl-filesize/#findComment-970925 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.