Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    New Coder
    Join Date
    Jan 2009
    Posts
    84
    Thanks
    5
    Thanked 0 Times in 0 Posts

    hello, making something only show on certain file types?

    Hello,

    On my file uploader i am using this code:

    PHP Code:
            <td class="table_header" colspan="2"><b>Your file(s) have been uploaded!</b> </td>
        </tr>
        <tr>
        <td class="table_body">
        <br />
    <?
    For($i=0$i <= $file_uploads-1$i++) {
        
        If(
    $_FILES['file']['name'][$i]) {
            
    $file=$i+1;
            
                    Echo(
    " <form name=\"select_all\"><div class=\"undertext\"></div><br><b>Direct Link #".$file.":</b> &nbsp;&nbsp;<a href=\"".$full_url.$file_name[$i]."\" target=\"imageloader\" class=\"gengoogle\">View uploaded image #".$file."</a>&nbsp;&nbsp;<a href=\"load.html\" target=\"imageloader\" class=\"gengoogle\">(Close img. ".$file.")</a><br><input type=\"text\" value=\"".$full_url.$file_name[$i]."\" onClick=\"javascript:this.form.direct_area".$file.".focus();this.form.direct_area".$file.".select();\" readonly size=\"41\" name=\"direct_area".$file."\">
     <br /><b>Forums Code #"
    .$file.":<br /></b><input type=\"text\" onClick=\"javascript:this.form.text_area".$file.".focus();this.form.text_area".$file.".select();\" readonly value=\"[img]".$full_url.$file_name[$i]."[/img]\" size=\"51\" name=\"text_area".$file."\" /><br /><br><hr><br>\n");
    I want this bit:

    PHP Code:
    <a href="".$full_url.$file_name[$i]."\" target=\"imageloader\" class=\"gengoogle\">View uploaded image #".$file."</a>&nbsp;&nbsp;<a href=\"load.html\" target=\"imageloader\" class=\"gengoogle\">(Close img. ".$file.")</a> 
    only to show on image files not files like .exe.... so it would show on jpg, jpeg, png, gif, bmp.

    How would i do it?

    Thanks

  • #2
    Regular Coder
    Join Date
    Jul 2002
    Location
    Canada, eh?
    Posts
    133
    Thanks
    2
    Thanked 3 Times in 3 Posts
    I use getimagesize() to check for image types. It will be false if it's not an image. So something like;

    PHP Code:
    $type = @getimagesize('/path/to/some/file.ext');
    if (
    $type && substr($type['mime'],0,6) == "image/") {
      
    // Show image.

    Bored? Might as well play Fantasian Kingdoms: http://www.fantasiankingdoms.com/

    Check out my JavaScript Image Project: http://codingforums.com/showthread.php?t=185231


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •