|
Posted by "Han" on 06/20/05 13:31
Hello,
I'm having a problem with a file upload. The following works on one server I
use : -
---------------------------------------------------------------------------
function add_me(){
global $filename;
global $maxFileSize;
global $yourdirectory;
// put this in a file that is called by your webpage with a form
// use the form file input type and call it 'file'
$maxFileSize = 204800;
$filename = $_FILES['file']['tmp_name'];
echo "f is ".$filename;
if (file_exists($filename))
{
// open the file
$handle = fopen($filename, "r");
// 1. read the file in line by line
while (!feof($handle))
{
$buffer = fgets($handle, 4096);
// if you were reading a text file you can
// do any operations on each line as you go here
}
// 2. otherwise just read the whole file
// in one go, e.g. for an image.
$buffer = fgets($handle, 4096);
// then you can write to the database or
// do whatever with it here
// close the file
fclose($handle);
}
$uploaddir = '/home/folder1/htdocs/folder2/'.myfolder.'/';
echo "<BR>YYYYYYYYYYY ".$uploaddir;
$uploadfile2 = $_FILES['file']['tmp_name'];
$uploadfile2 = preg_replace("/\/tmp\//", "", $uploadfile2);
$uploadfile = $uploaddir . $uploadfile2 .".gif";
//$$uploadfile2 =~ s/\/[a-zA-Z]\///g;
//print "<pre>";
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadfile)) {
print "File is valid, and was successfully uploaded. ";
} else {
print "Possible file upload attack! Here's some debugging info:\n";
}
//print "</pre>$uploadfile";
chmod($uploadfile,0777);
----------------------------------------------------------
But when I use this same code on a different server, it doesn't work as
there seem to be no $_FILES['file']['tmp_name'].
Is $_FILES['file']['tmp_name'] something configured by the server (I'm using
Apache on a Linux system), or something default within PHP itself?
Han.
Navigation:
[Reply to this message]
|