PDA

View Full Version : Question regarding fwrite(), filesize(), binary stream


lierduh
05-20-2004, 01:54 AM
I have the stream of the binary data. I need to use some file
associated function with it. For example filesize(), imagesize() etc.
At the moment, I write this data stream into a tmp file
fwrite('/tmp/tempfile', 'x+'), do the file functions, then unlink()
it. It surely is not an elegant way to do, let along a good
portability way.

Is there a way to create a file in the memory from the data stream? or
even use file functions without first write the stream into a file?
Thanks.

Velocd
05-20-2004, 10:03 PM
To get information about a file, without saving it to a permanent directory:


$file = $_FILES['file_input']['tmp_name']; // uploaded file to temporary directory on server
$file_size = $_FILES['file_input']['size'];


If this file was an image, you could also:


if (strpos($_FILES['userfile']['type'], 'image'))
$dimensions = @getimagesize($file); // returns array, index 0 = width, index 1 = height

lierduh
05-20-2004, 10:32 PM
To get information about a file, without saving it to a permanent directory:


Velocd, thanks for the reply.:)

Unfortunately this data stream does not come from a uploaded file. It is actually from decoded mime/uuencoded message.

May be I can find the temp directory enviroment within the script.

lierduh
05-22-2004, 06:45 AM
I have found you can actually write to $_FILES.:)

Also to find out the temp direcotory. The following code should help:

if (!$tmp_dir = get_cfg_var('upload_tmp_dir')) {
$tmp_dir = dirname(tempnam('', ''));
}