File not uploaded

Discussion in 'PHP' started by tanvirtonu, Nov 8, 2007.

  1. #1
    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.

    
    <?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>";
    		
    		}
    		
    		}
    		
    		
    ?>
    
    
    PHP:
    my html form code is as follws-
    
    <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></form>
    </body>
    
    HTML:
    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.
     
    tanvirtonu, Nov 8, 2007 IP
  2. redlorry919

    redlorry919 Peon

    Messages:
    384
    Likes Received:
    13
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Don't know if $dir="\uploadedFile";works. I've always done $dir="/uploadedFile"; since a backslash usually escapes things.
     
    redlorry919, Nov 8, 2007 IP
  3. bobb1589

    bobb1589 Peon

    Messages:
    289
    Likes Received:
    8
    Best Answers:
    0
    Trophy Points:
    0
    #3
    ^ should be your problem i would suggest putting the move_uploaded_file bit into an if statement to so it confirms that...

    <?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 uploaded<br>";
           
            }else{
            echo "file could not be uploaded.<br>";
           }
            }
           
           
    ?>
    PHP:
     
    bobb1589, Nov 8, 2007 IP
  4. tanvirtonu

    tanvirtonu Peon

    Messages:
    32
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I cud find out the simple mistake

    
    move_uploaded_file($filearray['tmp_name'], "$dir/{$filearray['name']}");
    
    PHP:
    Thnx all
     
    tanvirtonu, Nov 9, 2007 IP
  5. CEHonline

    CEHonline Peon

    Messages:
    5
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #5
    use the complete line:

    $uploaddir = '/sites/yoururl/uploaddir/';

    i think it would solve it.
     
    CEHonline, Nov 9, 2007 IP