-
How can I upload a file by php coding
Question asked by visitor Arnab
How can I upload a file by php coding?
I have been try it by xamapp .But the code is running local machine . but when I upload the code on the other server some where the code is not running.
my code as :
***************
if($_REQUEST['Submit']=='Submit')
{
if (($_FILES['fupload']['type'] == "image/gif")|| ($_FILES['fupload']['type'] == "image/jpeg")||($_FILES['fupload']['type'] == "image/pjpeg")){
$archive_dir="thum_imges";
echo $userfile=$_POST['fupload'];
echo "
";
echo $userfiled=$_FILES['fupload']['tmp_name'];
echo "
";
echo $filename=$_FILES['fupload']['name'];
echo "
";
$filenm=basename($filename);
// $up= copy($userfiled,"$archive_dir/$filenm") ;
$up= move_uploaded_file($userfiled,"$archive_dir/$filenm") ;
echo "
up = $up
";
}//End of file check if
}
?>
-
Junior Member
Re: How can I upload a file by php coding
first of all, try to avoid using REQUEST variable,
it is too "heavy", i mean in REQUEST You have POST and GET
so try to send form, especially files, only using POST
//////
second thing, try to debug using
var_dump
and try to find out, if those variables really exists
if the $_REQUEST['Submit']=='Submit'
if(isset($_REQUEST['Submit']) && $_REQUEST['Submit'] == 'Submit')
{
//here do You code
}
else
{
//echo "The form was incorrectly sent";
}
////
3rd problem which can occour, that You haven't granted
enough privileges for write access
///
4rd problem, on many servers the global variables
are turned off,
Hope You find those usefull
Charles
-
Junior Member
Re: How can I upload a file by php coding
we can upload a file using php.
if(is_uploaded_file($_FILES['yourfilename']['tmp_name'], pathname)
{
echo "file is already uploaded ";
move_uploaded_file($_FILES['yourfilename']['tmp_name'], pathname)
{
echo "replace the previous file from new file(having the same name) ";
}
}
else
{
echo "file is not uploaded so i need to upload a file first time";
}
and if u are upload a file first time . u have to write enctype='multiple/form-data'
inside a form tag.
BY
ANUJ MAHESHWARI
Last edited by anujm1_1; 08-21-2008 at 05:17 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules