note 17971 deleted from features.file-upload by irc-html

From: Date: Sat, 19 Jan 2002 20:36:56 +0000
Subject: note 17971 deleted from features.file-upload by irc-html
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-25385@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 :)

« previous php.notes (#25385) next »