tags:

views:

53

answers:

2

Lets say I have a PHP script that is going to serve a big file and I am currently uploading this big file through for example FTP.

Is there a way I can check in my PHP script if the upload is complete? Is there for example a way I can check if a file is currently being written to or something like that?

Update: Should have mentioned this before, but I'm not talking about uploading through an upload script I'm talking about for example uploading big pdf files or such through other means like FTP or SFTP.

+1  A: 

You can in upload script use a temportantly file (in temportantly directory) and if upload was finished you can simple move file to your final location with good filename.

This is a common solution for this problem.

For get temportantly file (enviroment independent) use PHP function:

resource tmpfile ( void )

Documemtation for it you can find at http://pl.php.net/manual/en/function.tmpfile.php This function returning handle to your new clean tempfile.

But if your using this function you must copy file before you close handle to it because this file was removed when you call fclose(handle). To get assurance of file buffer is clean you can at end call fflush(handle).


Or if you don't want use tmpfile(void) function you can do this manualy.

string tempnam ( string $dir, string $prefix )

Prefix is a prefix to your files to easly group her to delete or something. Call this function to get unique file in typed directory, as directory get you temp directory in your enviroment, you can get this by calling:

string sys_get_temp_dir ( void )

Then when you have self tempfile, write to it upload data and close. Copy this file to your final location using:

bool copy ( string $source, string $dest [, resource $context ] )

And delete your tempfile to get clean in your enviroment calling:

bool unlink ( string $filename [, resource $context ] )
Svisstack
A: 

You don't say which OS you're running on, but if you're on a Unix-like system, you can use fuser to see who's currently using a file. There's the handle which does the equivalent Windows-side.

Marc B