File Handles?
| From: | poliva at cox dot net | Date: | Sat, 14 Dec 2002 01:06:47 +0000 |
| Subject: | File Handles? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-128227@lists.php.net to get a copy of this message | ||
The following is a script from the php.net site for supposedly uploading files via ftp. My question
is, why do we have to build handles, what is the purpose of creating this array?
//Build handles for uploaded image
$imageUpFile = $_FILES['photo_file']['tmp_name'];
$imageType = $_FILES['photo_file']['type'];
$imageName = $_FILES['photo_file']['name'];
//Open the uploaded pic (temp file)
if ($thePic = fopen ($imageUpFile, "rb"))
{
//read temp file into var
$savePic = fread($thePic, filesize($imageUpFile));
//Open a new file in the correct directory using the name of the uploaded pic file
if ($fileHandle = fopen("ftp://username:password@put/directory/here/$imageName",
"w"))
{
//Put data into just opened file pointer
if (fwrite ($fileHandle, $savePic))
{
echo "file <b>$imageName</b> successfully written";
}
else
{
echo "file <b>$imageName</b> was NOT written";
}
}
fclose ($fileHandle);
fclose ($thePic);
}
else
{
// The file was not created. Inform the user.
echo ("<b> The file: $imageUpFile could not be created!</b>
");
}