I can't see an open for the input file, but presumably the file descriptor is coming from the query string? read usually returns zero when the file descriptor is at EOF. So either the file is empty, or the script that opened the file read it all, in which case you need to seek $file,0,0.