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 4 of 4
  1. #1
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts

    little problem with images - please help !

    Hi all !

    I am writinga simple image uploading script and want to display the image that is uploaded
    - preferably BEFORE it is sent by means of js.

    BUT i also have encountered a silly problem !


    First I can't get over this simple problem !!

    My server is set up as localhost on :d/web/

    in the following HTML file all the images show - as you'd expect !

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <title>Untitled</title>
    </head>
    <body>
    <img src="file:///D:/Web/fethiye/turkey.gif" border="2">
    <img src="http://localhost/fethiye/images/town.jpg" border="2">
    <img src="http://localhost/fethiye/turkey.gif" border="2">
    <img src="file:///D:/Web/fethiye/turkey.gif" border="2">
    </body>
    </html>


    BUT in my PHP file i get a problem - only the images with
    the http://localhost path are displayed the others

    with the file:/// path are broken ???

    Any one know why this is ?

    HERE is the php code

    UPLOAD.PHP calls UPLOAD_FORM.INC


    PHP Code:
    <?php
    /* upload.php
    * CALLS upload_form.inc
    */

    if (!isset($_POST[upload])) {
    $message1 = "Enter File Path";
    $message2 = " Now ";
    include ("upload_form.inc");
    } // endif
    else {
    if($_FILES['pix']['tmp_name'] == "none") {
    $message1 = "File did not successfully upload.";
    $message2 = "Check the file size. Must be less than 250K";
    include ("upload_form.inc");
    exit();
    } // endif

    if(!ereg("image",$_FILES['pix']['type'])) {
    $message1 = "File is not a picture file.";
    $message2 = "Please try a different file.";
    include ("upload_form.inc");
    exit();
    } // endif

    else {
    $destination = 'd:\web\data'."\\".$_FILES['pix']['name'];
    $temp_file = $_FILES['pix']['tmp_name'];
    move_uploaded_file($temp_file,$destination);
    $message1 = "File has been successfully uploaded.";
    $message2 = "CONGRATULATIONS !";
    include ("upload_form.inc");
    exit();
    } // end else
    } // end else

    ?>

    ------------------------------------------

    and now the form :


    PHP Code:
    <?php
    /* upload_form.inc
    * CALLED BY upload.php (and recalls it).
    */

    ?>

    HTML 4.01 Transitional//EN">
    <!-- Upload_form.inc
    Description : displays the a form for uploading data
    -->
    <html>
    <head>
    <title>Untitled</title>

    <script language="JavaScript" type="text/javascript">
    <!--
    function changeSrc1(who){
    img=who.replace(who.substring(0,1),'file:///'+who.substring(0,1));//add 'file:///' before the drive letter
    img=img.replace(/\\/g,'/');//replace all backslashes with forward slashes
    document.getElementById('preView1').src=img;
    } // end of function
    -->
    </script>

    </head>
    <body>

    <img src="file:///D:/Web/fethiye/turkey.gif" border="2">
    <img src="http://localhost/fethiye/images/town.jpg" border="2">
    <img src="http://localhost/fethiye/turkey.gif" border="2">
    <img src="file:///D:/Web/fethiye/turkey.gif" border="2">


    <div style='position:absolute; left:20px; top:60px'>
    <form enctype ="multipart/form-data" action="upload.php" method="POST">
    <input type="hidden" name ="MAX FILE SIZE" value="500000">
    <table width="400px" border="0" cellspacing="0" cellpadding="1">
    <tr>
    <td>Picture file path: </td>
    <td>
    <input type="file" id="x_pix1" size="50" onchange="changeSrc1(this.value)"
    name="pix" value = "<?php echo $x_pix1 ?>">
    </td></tr>

    <tr><td>
    <input type="submit" name="upload" value="Upload Picture">
    </td></tr>
    </table>
    </form>
    </div>

    <div id='PreView1' style='position:absolute; left:30px; top:200px' >
    <img id="preView1" width="120" height="120" />
    <br>
    - - - Picture 1 - - -
    </div>



    <div style='position:absolute; left:200px; top:300px'>
    <?php echo $message1 ?><br>
    <?php echo $message2 ?><br>
    </div>

    </body>
    </html>

    ---------------------------------------------------

    BTW the js script is not working yet - but thats another problem !

    Please help if you can !

    Thanks

  • #2
    Regular Coder
    Join Date
    May 2006
    Location
    Bristol, UK
    Posts
    147
    Thanks
    6
    Thanked 2 Times in 2 Posts
    hi mate,

    take a look at my site: Fartingfish

    it seems that i have already written exactly what you are trying to get working.

    Feel free to take a look at my source for ideas.

    Hope that helps

    Jon
    "You only live once, play it right, and once is enough" - me :)
    "When i die only god can take my soul" - me again! :P

  • #3
    Senior Coder
    Join Date
    May 2006
    Posts
    1,673
    Thanks
    28
    Thanked 4 Times in 4 Posts
    Hi Jon

    Thanks - i took a look at farting fish, great name!

    do you have any idae why i get problems with my he file:/// path
    images ??

    ALSO - have you ever tried to display an image BEFORE it is uploaded by using javascript ?

    thanks
    Dave.

  • #4
    Senior Coder
    Join Date
    Sep 2005
    Posts
    1,791
    Thanks
    5
    Thanked 36 Times in 35 Posts
    you can't use file:// references in websites you want to work through a server.


  •  

    Posting Permissions

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