Need urgent reply for move_uploaded_file function
Posted: Fri Nov 25, 2005 4:28 am
hi
I am working with php 4 on uploading files.
move_uploaded_file() and is_uploaded_file() is not working in php 4.can any one help me to overcome this problem.how can i upload files using php4.
I have tried to replace the function is_uploaded_file by the following function yet its not working.
I have downloaded this code from http://www.php.net/docs.php.
<?php
/* Userland test for uploaded file. */
function is_uploaded_file($filename) {
if (!$tmp_file = get_cfg_var('upload_tmp_dir')) {
$tmp_file = dirname(tempnam('', ''));
}
$tmp_file .= '/' . basename($filename);
/* User might have trailing slash in php.ini... */
return (ereg_replace('/+', '/', $tmp_file) == $filename);
}
/* This is how to use it, since you also don't have
* move_uploaded_file() in these older versions: */
if (is_uploaded_file($HTTP_POST_FILES['userfile'])) {
copy($HTTP_POST_FILES['userfile'], "/place/to/put/uploaded/file");
} else {
echo "Possible file upload attack: filename '$HTTP_POST_FILES[userfile]'.";
}
?>
I am working with php 4 on uploading files.
move_uploaded_file() and is_uploaded_file() is not working in php 4.can any one help me to overcome this problem.how can i upload files using php4.
I have tried to replace the function is_uploaded_file by the following function yet its not working.
I have downloaded this code from http://www.php.net/docs.php.
<?php
/* Userland test for uploaded file. */
function is_uploaded_file($filename) {
if (!$tmp_file = get_cfg_var('upload_tmp_dir')) {
$tmp_file = dirname(tempnam('', ''));
}
$tmp_file .= '/' . basename($filename);
/* User might have trailing slash in php.ini... */
return (ereg_replace('/+', '/', $tmp_file) == $filename);
}
/* This is how to use it, since you also don't have
* move_uploaded_file() in these older versions: */
if (is_uploaded_file($HTTP_POST_FILES['userfile'])) {
copy($HTTP_POST_FILES['userfile'], "/place/to/put/uploaded/file");
} else {
echo "Possible file upload attack: filename '$HTTP_POST_FILES[userfile]'.";
}
?>
Code: Select all