开发者

PHP uploads and checking

Edited:

Sorry for the inconvenience, when i look back the codes, it does not actually upload the files, it's only capture the file's info and store in the database, which later cannot be download by user coz there not exist such file anywhere... my questions is, how can i integrate this codes with move_uploaded_file() function?


I want to update/insert file by using upload box to the database but before that it will check for the file type thats only pdf can be upload. Somthing wrong with the codes and i dont know what..Please help

here are part of my updates codes:

$id=$rs['id']; 
$qry = "SELECT a.faillampiran FROM {$CFG->prefix}ptk_lampiran a, {$CFG->prefix}ptk b WHERE a.ptkid=$id and b.id=$id";

$sql = get_records_sql($qry);
if($_POST['check']){     
    $ext = pathinfo($faillampiran,PATHINFO_EXTENSION);      
    $err = "Upload Only PDF File. ";    
    if ($ext =='pdf'){          
        $qry="UPDATE {$CFG->prefix}ptk_lampiran SET 
        faillampiran='".$faillampiran."'                
        WHERE ptkid='".$_GET['id']."'";
        $sql=mysql_query($qry)开发者_StackOverflow社区;     
        $qry = "SELECT a.faillampiran FROM {$CFG->prefix}ptk_lampiran a, {$CFG->prefix}ptk b
            WHERE b.id = '".$rs[id]."' AND a.ptkid = '".$rs[id]."' ";
        $sql = get_records_sql($qry);
        foreach($sql as $rs){ ?>              
            <?=basename($rs->faillampiran); ?><br>
        <? } 
        ?>              
        <tr><td></td><td></td><td>
        <input type="file" size="50" name="faillampiran" alt="faillampiran" value= "<?=$faillampiran;?>" />
        <input type="submit" name="edit" value="Muat naik fail ini" /><br />
        </td></tr>  
    }       
    else {
        echo "<script>alert('$err')</script>";
    }

} else { 

foreach($sql as $rs){ ?>              
    <?=basename($rs->faillampiran); ?><br>
<? } 

?>
<input type="file" size="50" name="faillampiran" alt="faillampiran" value= "<?=$faillampiran;?>" />
<input type="submit" name="edit" value="Muat naik fail ini" /><br />
<?}

Sori bout the messiness of the codes, im still a beginner in this languages.

thx


You've provided no details of why you think it fails.

However using my crystal ball, I see that you are checking if the file extension is '.pdf'. I guess you're looking at $_FILES['userfile']['tmp_name'] or $_FILES['userfile']['name']. The latter will only match if the extension was in lower case on the client. The former won't ever match.

it will check for the file type thats only pdf

That's not what your code does at all. A file extension only matches the contents by convention and only on some architectures

C.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜