note 17971 added to features.file-upload
| From: | robert at simp-tech dot com | Date: | Sat, 05 Jan 2002 16:23:38 +0000 |
| Subject: | note 17971 added to features.file-upload | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-24429@lists.php.net to get a copy of this message | ||
Since my site is hosted through another company, I had to "work around" limitations that
they would not change. Particularly, not being able to copy or move the file that was stored in the
"tmp" folder :(
In order to get around this problem, I read the contents of the file and wrote them to the file in
the desired location in my directories. This took me a couple of hours to come up with once I
realized that my host would not increase my permissions on thier server. I hope that this helps
someone else...
if (is_uploaded_file($userfile)) {
// Read the temporary file
$fd1 = @fopen ($userfile, "rb");
if ($fd1) {
$contents = fread ($fd1, $userfile_size);
fclose ($fd1);
if ($contents) {
echo "The contents of the file have been loaded.<br />";
} else {
echo "<h1>Failed to load contents of the file!</h1><br />";
die;
}
} else {
echo "<h1>Failed to open the temporary file for read-only binary
access!</h1><br />";
die;
}
// Write the local file
$fd2 = fopen ("../tmp/".$userfile_name, "ab");
if ($fd2) {
$success = fwrite ($fd2, $contents);
if ($success) {
echo "The file has been written to the server!<br />";
echo "<a href='../tmp/$userfile_name'>Click here</a> to download
the file.<br />";
} else {
echo "<h1>The contents of the file could not be processed!</h1><br
/>";
}
fclose ($fd2);
} else {
echo "<h1>The file could not be created!</h1><br />";
}
}
Note: "../tmp" has to be a directory relative to the location of the script!
Probably just me, but I always prefer to program in the positive. i.e., Check for true results
before false :)
--
http://www.php.net/manual/en/features.file-upload.php
http://master.php.net/manage/user-notes.php?action=edit+17971
http://master.php.net/manage/user-notes.php?action=delete+17971
http://master.php.net/manage/user-notes.php?action=reject+17971