Reading file contents from temp
Posted: Mon Nov 28, 2005 10:42 pm
Hello all!
I'm trying to save the contents of a file in its submitted temporary location to a string.
Here's what my code looks like:
Here's what I get when I try to upload test.txt:
Anyone know what's wrong?
I'm trying to save the contents of a file in its submitted temporary location to a string.
Here's what my code looks like:
Code: Select all
<?php
/* In my HTML
<form action="upload.php" method="post" enctype="multipart/form-data">
<label for="file"></label>
<p align="center">
<input type="file" name="file" id="file">
<br>
<input type="submit" name="submit" value="Submit File"><br>
<b><font face="Arial" size="1">might not be working yet</font></b>
</p>
</form>
*/
print_r($_FILES['file']);
$filename = $_FILES['file']['name'];
$fileloc = $_FILES['file']['tmp_name'];
$newloc = '/var/www/users/myserver/public_html/files/';
chmod($fileloc,777);
$string = file_get_contents($fileloc);
//check to see if file was read from tmp
if ($string == "")
{
$string = "[No Contents]\nError reading $filename from its temporary location.\n";
}
//move file
if (move_uploaded_file($fileloc,$newloc.$filename))
{
$string = "File succesfully moved\n".$string;
}
else {
$string = $string."Error moving $filename from $fileloc\n";}
//check to see if file was read from new location
$oldstring = $string;
$string2 = file_get_contents($newloc);
$string = $string2.$string;
if($oldstring == $string)
{
$string = $string."Error reading $filename from its new location. You're truly out of luck...";
}
include('output.php');
?>Code: Select all
[No Contents]
Error reading FILE.txt from its temporary location.
Error moving FILE.txt from /tmp/phplsBFf30838
Error reading FILE.txt from its new location. You're truly out of luck...