PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
tanvirtonu
Forum Commoner
Posts: 35 Joined: Wed Oct 17, 2007 9:15 am
Post
by tanvirtonu » Thu Nov 08, 2007 3:12 am
I have written a simple php code to upload a file . There is no error when I run the code but file is not uploaded in the specified directory.
Code: Select all
<?php
$dir="\uploadedFile";
foreach($_FILES as $filename => $filearray )
{
echo $filearray['tmp_name']."<br>";
echo $filearray['name']."<br>";
echo $filearray['size']."<br>";
echo $filearray['type']."<br>";
if( is_uploaded_file($filearray['tmp_name'] ) )
{
move_uploaded_file( $filearray['tmp_name'] , "$dir\$filearray[name]" );
echo " file is uploded<br>";
}
}
?>
my html form code is as follows-
Code: Select all
<body>
<form action="fileupform.php" enctype="multipart/form-data" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="51200">
<input type="file" name="fileupload">
<p> <input type="submit" value="upload" >
</p>
</body>
I hav made a directory named uploadedFile in htdocs folder. The name as specified for the destination directory.Everything goes well but the file is not there in the directory. PLs help me.
Christopher
Site Administrator
Posts: 13596 Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US
Post
by Christopher » Thu Nov 08, 2007 3:30 am
Try:
Code: Select all
move_uploaded_file($filearray['tmp_name'], "$dir/{$filearray['name']}");
Last edited by
Christopher on Thu Nov 08, 2007 4:15 am, edited 7 times in total.
(#10850)
CoderGoblin
DevNet Resident
Posts: 1425 Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany
Post
by CoderGoblin » Thu Nov 08, 2007 3:57 am
Try to always quote your array indexes if not numeric...
Code: Select all
move_uploaded_file($filearray['tmp_name'], "$dir/{$filearray['name']}");Doing so will avoid a PHP notice if you ever switch logging on.
In case you are wondering about the squiggly brackets look
here at php manual
tanvirtonu
Forum Commoner
Posts: 35 Joined: Wed Oct 17, 2007 9:15 am
Post
by tanvirtonu » Fri Nov 09, 2007 6:16 am
It is working now
arborint wrote: Try:
Code: Select all
move_uploaded_file($filearray['tmp_name'], "$dir/{$filearray['name']}");
THNX ALL
Zoxive
Forum Regular
Posts: 974 Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan
Post
by Zoxive » Fri Nov 09, 2007 8:12 am
And you can also add another check to see if the file actually gets moved to the folder.
Code: Select all
$Moved = move_uploaded_file($filearray['tmp_name'], "$dir/{$filearray['name']}");
if($Moved){
// Success
}else{
// Could not move the file.. most likely folder permisions
}