Page 1 of 2 12 LastLast
Results 1 to 10 of 18

Thread: images on file extentions... Need help!

  1. #1
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default images on file extentions... Need help!

    Hi, i have an idea to create php script which regonises the uploaded file extention. What is more, if my file was xxx.txt then it will show picture 1, if xxx.png - picture 2, if xxx.zip - picture 3 and etc. If you need more info, ASK Thanks a LOT
    Last edited by auriaks; 11-11-2009 at 12:13 AM.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Set up a normal file uploads script.

    Once you do this, the filename will be available as a variable in PHP. Using this, you can just split the string and get whatever is after the ., so jpg, gif, etc. (substr(), for example).

    As for "displaying" an image, you just need to set up an array with filetypes to images:
    PHP Code:
    $extimgs = array(
    'jpg' => '1.jpg',
    'gif' => '2.jpg'

    Find the image, display it wherever you'd like.


    If you need more specific information you will need to show us code or tell us exactly where you want the image to show up, how you will access the filename, etc.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    My form:
    PHP Code:
    <form enctype="multipart/form-data" action="redirect_upload/uploader_talpykla.php" method="POST">
    <
    input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
    <
    span style="font-size: 10.0pt; font-family: 'Times New Roman',serif">
    Send us: <input name="uploadedfile" type="file" />
    <
    input type="submit" value="Siųsti" /><br>
    </
    span>
    </
    form
    My php for storing:
    PHP Code:
    <?php

    // Where the file is going to be placed 
    $target_path "talpykla/";

    /* Add the original filename to our target path.  
    Result is "uploads/filename.extension" */
    $target_path $target_path basename$_FILES['uploadedfile']['name']); 


    //Checking
    $target_path "talpykla/";

    $target_path $target_path basename$_FILES['uploadedfile']['name']); 

    if(
    move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        
    header("location:up_yes1.php");
    } else{
        
    header("location:up_no1.php");
    }
    ?>
    Can you change it?? Thx

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    PHP Code:
    $name basename$_FILES['uploadedfile']['name']); //this is the variable you want
    $ext substr($name,strrpos($name,'.')); //get the part after the last .
    $images = array( //setup an array of exts=>images
    'jpg' => 'jpeg.gif',
    'gif' => 'mygifimage.gif',
    ... 
    //add as many as you need
    'pdf' => 'documentimage.gif'
    ); //ok, that's setup
    if (isset($images[$ext])) { //is the file extension valid, do we have an image?
       
    echo $images[$ext]; //it will print out jpeg.gif for ext .jpg, etc.

    Print out the image within an image tag or whatever you want.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    Thank you I think it will work, but idk where to put your script... in my uploading file or other which i use to show the file's picture?

    my full uploading script: (uploader_talpykla.php)
    PHP Code:
    <?php

    // Where the file is going to be placed 
    $target_path "talpykla/";

    /* Add the original filename to our target path.  
    Result is "uploads/filename.extension" */
    $target_path $target_path basename$_FILES['uploadedfile']['name']); 


    //Checking
    $target_path "talpykla/";

    $target_path $target_path basename$_FILES['uploadedfile']['name']); 

    if(
    move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
        
    header("location:up_yes.php");
    } else{
        
    header("location:up_no.php");
    }
    ?>
    I tried so many ways to put your script in this, but all i got was EMPTY uploader_talpykla.php window.

    BTW, i stored pictures in 'src/pic.jpg'. its one of 5 pictures i have.

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    You are sending out a header to change the location-- a redirect. Of course nothing will show up on the page. Remove header("location:up_yes.php"); and replace it with my code. That will just display the image, though. But if you want something more, you will have to redesign your site.
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    i tried this... - empty page Maybe i need those pictures to be shown in next page. I thought about saving name into mysql variable and call it in the next page. but idk how to use your script then.

  8. #8
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    i solved extension problem, but still one smller appeared...
    PHP Code:
    echo 
        <table width='120px';>     
            <tr>
            <td>
            &nbsp;<img src='redirect_upload/uploads/
    $filename' width='80px' height='70px' border='0'>
            <font size='0.8' face='Verdana' color='blue'><b>
            Pavadinimas:&nbsp; 
    $name <br>
            Idejo:&nbsp;&nbsp; 
    $nick       <br>                            
            Data:&nbsp;&nbsp;&nbsp; 
    $date  <br>
            Rusis:&nbsp;&nbsp; 
    $type
            </b></font>
            </td>
            </tr>
        </table> 
        "

    This is my script for writing info from mysql to webpage. Here's the problem: It writes information 3 times in one column, but i need them horizontal... now its like:

    TEXT
    TEXT
    TEXT

    i need:

    TEXT TEXT TEXT

    Thanks...

  9. #9
    Join Date
    May 2007
    Location
    Boston,ma
    Posts
    2,127
    Thanks
    173
    Thanked 207 Times in 205 Posts

    Default

    Take out the <br>'s

  10. #10
    Join Date
    Aug 2009
    Posts
    399
    Thanks
    42
    Thanked 4 Times in 4 Posts

    Default

    i mean else now it is :
    picture
    text
    text
    text

    picture
    text
    text
    text

    picture
    text
    text
    text

    i want:
    picture picture picture
    text text text
    text text text
    text text text

    my command repeats all the script 3 times

Bookmarks

Posting Permissions

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