doc or pdf file upload to use php script

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Noorain
    New Member
    • Mar 2008
    • 57

    doc or pdf file upload to use php script

    Sir

    I want to CV(doc or pdf format) upload in database. Locally its script run my server but when i hosting it doesn't work. file doesn't upload. Its display, File format is wrong, please try again. please help me............. ...



    [PHP]

    $cv = $_FILES['cv']['name'];
    $allowed_ext = "doc, pdf"; // These are the allowed extensions of the files that are uploaded
    // Check Entension

    $extension = pathinfo($HTTP_ POST_FILES['cv']['name']);
    $extension = $extension[extension];
    $allowed_paths = explode(", ", $allowed_ext);
    for($i = 0; $i < count($allowed_ paths); $i++) {
    if ($allowed_paths[$i] == "$extension ") {
    $ok = "1";
    }}

    if($ok == "1")
    {
    // Copy File
    $MAX_FILE_SIZE = $HTTP_POST_VARS['MAX_FILE_SIZE'];
    $time = time(); // time is used to ensure unique file name
    $original_path = "current-job/".$HTTP_POST_FI LES['cv']['name'];
    //use for checking upload file
    if (!(move_uploade d_file($HTTP_PO ST_FILES['cv']['tmp_name'], $original_path) ))
    {
    $msg = "<font color='#CC0000' >Error in copy File, Please try again.</font><br><br><i nput name='button' type='Button' onClick='javasc riot:history.go (-1)' value='Back' src='button' +>";
    }
    else
    {
    $m=$_POST['m'];
    $d=$_POST['d'];
    $y=$_POST['y'];
    $gAppli_dob=$d;
    $gAppli_dob.=" ";
    $gAppli_dob.=$m ;
    $gAppli_dob.=", ";
    $gAppli_dob.=$y ;

    $sql = "select * from `job_appli` where job_id='$gjob_i d' and name='$gName'";
    $result = mysql_query($sq l) or die ("unable to $sql");
    $affect = mysql_affected_ rows();
    if ($affect > 0)
    {
    $msg= "<font color='#CC0000' >Information already exists.</font><br><br><i nput name='button' type='Button' onClick='javasc riot:history.go (-1)' value='Back' src='button' +><br>";

    }
    else
    {
    $sql = "INSERT INTO `job_appli` (`job_id`,`name `,`appli_id`,`a ppli_dob`,`appl i_sex`,`appli_p hone`,`appli_em ail`,`appli_fr` ,`appli_org`,`a ppli_posi`,`app li_ini_posi`,`c v`) VALUES('$gjob_i d','$gName','$g Appli_id','$gAp pli_dob','$gApp li_sex','$gAppl i_phone','$gApp li_email','$gAp pli_fr','$gAppl i_org','$gAppli _posi','$gAppli _ini_posi','$cv ')";
    $result = mysql_query($sq l) or die ("unable to $sql");
    $msg = "Your information has been Submitted Successfully.<b r>";
    }
    }
    }
    else
    {
    $msg = "<font color='#CC0000' >File format is wrong, please try again.</font><br><br><i nput name='button' type='Button' onClick='javasc riot:history.go (-1)' value='Back' src='button' +>";
    }

    [/PHP]

    Thanks
    Noorain
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hi.

    Line 6
    [code=php]
    // This...
    $extension = $extension[extension];
    // Should be...
    $extension = $extension['extension'];
    [/code]
    Array elements should always be quoted
    Except maybe when used in strings, but thats an entirely different discussion.

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Ac couple of suggestions...

      You could create an array containing the valid extensions and use the in_array function to search it for you.
      Would get rid of the extra for loop there.

      You seem to use $HTTP_POST_FILE S and $HTTP_POST_VARS arrays ever now and then throughout your code.
      They are both deprecated and should not be used.
      The $_POST and $_FILES super-globals should be used instead.

      Comment

      • Noorain
        New Member
        • Mar 2008
        • 57

        #4
        Originally posted by Atli
        Hi.

        Line 6
        [code=php]
        // This...
        $extension = $extension[extension];
        // Should be...
        $extension = $extension['extension'];
        [/code]
        Array elements should always be quoted
        Except maybe when used in strings, but thats an entirely different discussion.

        Thanks. but line 5 doesn't work.pathinfo() doesn't work in php 2.6.0. Please help me.

        Comment

        • Atli
          Recognized Expert Expert
          • Nov 2006
          • 5062

          #5
          Originally posted by Noorain
          Thanks. but line 5 doesn't work.pathinfo() doesn't work in php 2.6.0. Please help me.
          Are you seriously using PHP 2?! I don't believe you! :P
          That was released in like 1996, while it was still just a one man operation.

          If that is the case... update to PHP 5!
          I doubt anybody can help you if you are really using PHP2. It's just way to old.

          Comment

          Working...