what's wrong in my code?

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

Post Reply
<?erick?>
Forum Newbie
Posts: 12
Joined: Thu May 29, 2008 8:36 am

what's wrong in my code?

Post by <?erick?> »

what's wrong in my code? bec. when i trying to add attachment it is always failed. i cant add to database also the path directory..

Code: Select all

 
<?
if(isset($_POST['upload']))
{
    $file['file']=$_FILES['file']['tmp_name'];
    $file['size']=$_FILES['file']['size'];
    $ext='';
    $file['extent'] = pathinfo(strtolower($_FILES['file']['name'])); 
    $file['name']=(isset($file['extent']['extension'])) ? strtolower($user.".".$file['extent']['extension']) : '';
    $uploadDir = 'my directory';
        if(is_uploaded_file($_FILES['file']['tmp_name']))
        {
        move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.$file['name']);
        }
        }
//db
    $query = "INSERT INTO upload (name, size, type, path) ".
             "VALUES ('$fileName', '$fileSize', '$fileType', '$filePath')";
    mysql_query($query) or die('Error, query failed :' . mysql_error());   
                     
    
        
?>
<form action="" method="post">
  <table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
    <tr> 
      <td width="246"><input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="file" type="file" class="box" id="file">
         </td>
      <td width="80"><input name="upload" type="submit" class="box" id="upload" value="Upload"></td>
    </tr>
  </table>
</form>
 
WebbieDave
Forum Contributor
Posts: 213
Joined: Sun Jul 15, 2007 7:07 am

Re: what's wrong in my code?

Post by WebbieDave »

What errors/warnings are you receiving? Place the following at the top of your script:

Code: Select all

ini_set('display_errors', 1);
error_reporting(E_ALL);
That should shed some light on what's wrong in your code.
ragnis12
Forum Newbie
Posts: 12
Joined: Tue Jun 17, 2008 4:14 am

Re: what's wrong in my code?

Post by ragnis12 »

Code: Select all

 
 <?php
 if(isset($_POST['upload']))
 {
     $file = array();
     $file['file'] = $_FILES['file']['tmp_name'];
     $file['size'] = $_FILES['file']['size'];
     $ext = '';
     $file['extent'] = pathinfo(strtolower($_FILES['file']['name']));
     $file['name'] = (isset($file['extent']['extension'])) ? strtolower($user.".".$file['extent']['extension']) : '';
     $uploadDir = 'my directory';
         if(is_uploaded_file($_FILES['file']['tmp_name']))
         {
         move_uploaded_file($_FILES['file']['tmp_name'],$uploaddir.$file['name']);
         }
         }
 //db
     $query = "INSERT INTO upload (name, size, type, path) ".
              "VALUES ('$fileName', '$fileSize', '$fileType', '$filePath')";
     mysql_query($query) or die('Error, query failed :' . mysql_error());  
                      
   
        
 ?>
 <form action="" method="post" enctype="multipart/form-data">
   <table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
     <tr>
       <td width="246"><input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="file" type="file" class="box" id="file">
          </td>
       <td width="80"><input name="upload" type="submit" class="box" id="upload" value="Upload"></td>
     </tr>
   </table>
 </form>
 
 
<?erick?>
Forum Newbie
Posts: 12
Joined: Thu May 29, 2008 8:36 am

Re: what's wrong in my code?

Post by <?erick?> »

hello i got error please see.. please help me to solve this problem.
Notice: Undefined index: file in C:\website\uhd_4_edit\requestor.php on line 123

Notice: Undefined index: file in C:\website\uhd_4_edit\requestor.php on line 134

Notice: Undefined index: file in C:\website\uhd_4_edit\requestor.php on line 173

ragnis12
Forum Newbie
Posts: 12
Joined: Tue Jun 17, 2008 4:14 am

Re: what's wrong in my code?

Post by ragnis12 »

can we see that file?
Post Reply