"Chung Leong" <ch***********@hotmail.com> wrote in message news:<ef********************@comcast.com>...
"Agelmar" <if**********@comcast.net> wrote in message
news:c4*************@ID-30799.news.uni-berlin.de... Amy Kimber wrote: Hello,
I have a file upload page, and I've had it working fine, it was
beautiful :-) Anyway, the powers that be moved hosts... and it doesn't
work now.
The file name is correct, the directory where it's going on the
server is correct (checked through prints etc.). I've changed the dir
to 777 (is that right?) and this is what I get on the
print_r($_FILES); line:
Array
(
[userfile] => Array
(
[name] => index.html
[type] => text/plain
[tmp_name] => /tmp/phpccPHUE
[error] => 0
[size] => 39
)
)
And the file is not uploading - I'm getting an error on the line:
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) <snip>
What is the value of $uploadfile?
$uploadfile = $uploaddir . $_FILES['userfile']['name'];
which comes out as...
/web/demo/translation/index.html
which seems correct,
And what is the error?
that's just hte point, [error] => 0 - but the line that's throwing the
error is:
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
{
I have had this code working before on another server, so what am I
doing wrong? Please! Any comments at all would be useful!
:-)
Many thanks,
Amy
here's the whole code
---------------------
<?php
session_start();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>File upload</title>
<meta http-equiv="Content-Type" content="text/html;
charset=iso-8859-1" />
</head>
<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used
instead
// of $_FILES. In PHP versions earlier than 4.0.3, use copy() and
// is_uploaded_file() instead of move_uploaded_file.
$uploaddir = '/web/demo/translation/';
$uploadfile = $uploaddir . $_FILES['userfile']['name'];
print ($uploadfile);
print ($_FILES['userfile']['name']);
print "<pre>";
print_r($_FILES);
print ("name: " . $uploadfile);
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
{
$msg = "File (" . $_FILES['userfile']['name'] . ") is valid, and
was successfully uploaded. ";
//print_r($_FILES);
$jobid = time();
$rename = $jobid . $_FILES['userfile']['name']; //or $rename =
$username;
$file_name = $_FILES['userfile']['name'];
$read_extension = explode(".", $file_name);
$ext = $read_extension[1];
//$rename = $rename.".".$ext;
rename($file_name, $rename);
$info = array($rename, $_FILES['userfile']['type']);
session_register('info');
session_start();
} else {
$msg = "File did not upload successfully, close window and try
againn";
$msg = $msg . print_r($_FILES);
}
?>
<BODY bgColor=#ffffff >
etc. etc.
----------------------
and the output is this:
------------
/web/demo/translation/index.html
index.html
Array
(
[userfile] => Array
(
[name] => index.html
[type] => text/html
[tmp_name] => /tmp/phpEyvvil
[error] => 0
[size] => 477
)
)
name: /web/demo/translation/index.html
Array
(
[userfile] => Array
(
[name] => index.html
[type] => text/html
[tmp_name] => /tmp/phpEyvvil
[error] => 0
[size] => 477
)
)
Upload File File did not upload successfully, close window and try
againn1