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 10 of 10
  1. #1
    New Coder
    Join Date
    Jan 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Changing the upload destination?

    Hey Guys,

    Ok so iv been playing around with a upload script and all is working fine and they are uploading to my /images/ folder. but i want the images to upload to a /file.html/ so they are public.
    The image below is how i want them to be displayed.



    At the moment i have a blank .html file, the upload script in a .php file and my styles folder.

    Heres the upload script;

    Code:
    <?php
    /*************************************************
     * Uploader
     *
     * This was coded by james addison and is aloud to be used by anyone who leaves the copyright there
     * 
     ****************************************************/
    
    //Windows way
    $uploadLocation = "./";
    //Unix, Linux way
    //$uploadLocation = "\tmp";
    
    ?>
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
    <html>
    <head>
       <title>Uploader!</title>
       <link href="style/style.css" rel="stylesheet" type="text/css" />
       <style type="text/css">
    <!--
    .style1 {
    	font-size: 10px;
    	font-weight: bold;
    }
    -->
       </style>
    </head>
    <body>
        <div id="main">
          <div id="caption">UPLOAD FILE</div>
          <div id="icon">&nbsp;</div>
          <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="fileForm" id="fileForm" enctype="multipart/form-data">
            File to upload:<center>
            <table>
              <tr><td><input name="upfile" type="file" size="36"></td></tr>
              <tr><td align="center"><p><br/>
                <input class="text" type="submit" name="submitBtn" value="Upload">
              </p>
                  <p align="right" class="style1"><a href="http://hosting-town.com">Made By Hosting-Town.com - James Addison </a></p></td>
              </tr>
            </table></center>  
          </form>
    <?php    
        if (isset($_POST['submitBtn'])){
    
    ?>
          <div id="caption">RESULT</div>
          <div id="icon2">&nbsp;</div>
          <div id="result">
            <table width="100%">
    <?php
    
    $target_path = $_SERVER['DOCUMENT_ROOT'] . '/images/' . basename( $_FILES['upfile']['name']);
    if(move_uploaded_file($_FILES['upfile']['tmp_name'], $target_path)) {
        echo "The file".  basename( $_FILES['upfile']['name']).
        "has been sucessfully uploaded.";
    } else{
        echo "There was an error uploading the file, please try again!";
    }
    
    ?>
            </table>
         </div>
    <?php            
        }
    ?>
        <div>
    	
    	Please note: You are solely responsible for any content that you may choose to upload to this site.  The site owner/administrator will not accept ANY responsibility regarding illegal content that you upload.  Should you not agree to these terms, please leave this page now.
    </body>
    Im really not sure what to do but i have a feeling it has something to do with
    Code:
    $target_path = $_SERVER['DOCUMENT_ROOT'] . '/images/' . basename( $_FILES['upfile']['name']);
    Thanks

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,864
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    but i want the images to upload to a /file.html/ so they are public.
    You can't upload a file into a file!

    You need to write some server side code in that file to list the images in it. btw, you'd need to rename your file to file.php to execute the PHP code written in it.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    New Coder
    Join Date
    Jan 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    You can't upload a file into a file!

    You need to write some server side code in that file to list the images in it. btw, you'd need to rename your file to file.php to execute the PHP code written in it.

    mmm ok well is there some server side code on the net that i could copy? Iv never dealt with that before. Or does anyone on here have one?

    Cheers

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,864
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Or does anyone on here have one?
    You could use the glob() function to grab all images from a directory and then use a loop (say foreach()) to display them using <img> tags.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #5
    New Coder
    Join Date
    Jan 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    You could use the glob() function to grab all images from a directory and then use a loop (say foreach()) to display them using <img> tags.
    How would you place them in the image tags? Im sorry im only a newby

    could you give me an example please?




    Cheers

  • #6
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,864
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Try something like
    PHP Code:
    <?php
    $images
    =glob($_SERVER['DOCUMENT_ROOT'] . '/images/*.{jpg,png,gif}',GLOB_BRACE);
    foreach(
    $images as $image){
        
    $size=getimagesize($image);
        echo 
    '<img src="images/'.basename($image).'" width="'.$size[0].'" height="'.$size[1].'" >';
    }

    ?>
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #7
    New Coder
    Join Date
    Jan 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    Try something like
    PHP Code:
    <?php
    $images
    =glob($_SERVER['DOCUMENT_ROOT'] . '/images/*.{jpg,png,gif}',GLOB_BRACE);
    foreach(
    $images as $image){
        
    $size=getimagesize($image);
        echo 
    '<img src="images/'.basename($image).'" width="'.$size[0].'" height="'.$size[1].'" >';
    }

    ?>

    Awesome, thank you so so much

    Now how could i make a default size? Also do you know how i would position them like this image?


  • #8
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,864
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    Now how could i make a default size?
    In order to keep the proportion, you'd need to resize the image at the time of upload. Otherwise, you may set a fixed width and height values while echoing the images.

    Also do you know how i would position them like this image?
    Echo a line break (<br>) after every two images inside the loop.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #9
    New Coder
    Join Date
    Jan 2012
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    In order to keep the proportion, you'd need to resize the image at the time of upload. Otherwise, you may set a fixed width and height values while echoing the images.


    Echo a line break (<br>) after every two images inside the loop.
    Could you show me what you mean?

  • #10
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,864
    Thanks
    160
    Thanked 2,224 Times in 2,211 Posts
    PHP Code:
    <?php
    $images
    =glob($_SERVER['DOCUMENT_ROOT'] . '/images/*.{jpg,png,gif}',GLOB_BRACE);
    $i=0;
    foreach(
    $images as $image){    
        echo 
    '<img src="images/'.basename($image).'" width="230" height="100" >';
        
    $i++;
        if(
    $i%2==0) echo '<br>';
    }

    ?>
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)


  •  

    Posting Permissions

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