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
    Regular Coder
    Join Date
    May 2011
    Posts
    122
    Thanks
    23
    Thanked 0 Times in 0 Posts

    Uploading not working

    I have this code:

    PHP Code:
    <form action="/index.php?page=site_add" method="post">
        <table class="box">
            <thead>
                <tr>
                    <th colspan="2">Add Your Schematic</th>
                </tr>
            </thead>
            <tbody>
                <tr>
                    <td>Schematic Name:</td>
                    <td>
                        <input type="text" class="input" name="site_name" value="" />
                        <img src="/images/info.png" class="tooltip" title="The name of your schematic/build." />
                    </td>
                </tr>
                <tr>
                    <td>Your Schematic:</td>
                    <td>
                        <input name="site_url" type="file" />

    <?php
     $target 
    "schematics/"
     
    $target $target basename$_FILES['site_url']['name']) ; 
     
    $ok=1
     if(
    move_uploaded_file($_FILES['site_url']['tmp_name'], $target)) 
     {
     echo 
    "The file "basename$_FILES['site_url']['name']). " has been uploaded";
     } 
    ?>
                        <img src="/images/info.png" class="tooltip" title="The Schematic of your uploading..." />
                    </td>
                </tr>
                <tr>
                    <td>Version:</td>
                    <td>
                        <input type="text" class="input" name="site_banner" value="" />
                        <img src="/images/info.png" class="tooltip" title="Include your schematic version." />
                    </td>
                </tr>
                <tr>
                    <td>Schematic Description:</td>
                    <td>
                        <textarea class="textarea" name="site_description"></textarea>
                        <img src="/images/info.png" class="tooltip" title="A detailed description of your schematic." />
                    </td>
                </tr>
            </tbody>
            <tfoot>
                <tr>
                    <td colspan="2"><input type="submit" name="submit" value="Upload Schematic" class="button" /></td>
                </tr>
            </tfoot>
        </table>
    </form>
    Can you point out what's wrong? I'm uploading a file (.schematic) and it's not being uploaded.

  • #2
    New Coder
    Join Date
    Jun 2011
    Location
    Australia
    Posts
    13
    Thanks
    3
    Thanked 1 Time in 1 Post
    I'm still a newbie to PHP but I can see one problem. In the <form> tag you need to include enctype="multipart/form-data" otherwise it wont accept files.

  • Users who have thanked Scyko for this post:

    Xaqa (08-27-2011)

  • #3
    Banned
    Join Date
    Apr 2011
    Posts
    656
    Thanks
    14
    Thanked 69 Times in 69 Posts
    also, if this is going onto a non local web server, some ISP's don't by default allow files to be uploaded. If pain persists, check with your ISP.

  • #4
    Regular Coder
    Join Date
    May 2011
    Posts
    122
    Thanks
    23
    Thanked 0 Times in 0 Posts
    Okay I got that to work, now what I want is the name of the file to be the value of the input so I'm trying to to do this:

    PHP Code:
                    <td>Your Schematic:</td>
                    <td>
                        <input name="site1" type="file" class="input" />
                                                                            

    <?php
     $target 
    "schematics/"
     
    $target $target basename$_FILES['site1']['name']) ; 
     
    $ok=1
     if(
    move_uploaded_file($_FILES['site1']['tmp_name'], $target)) 
     {
     echo 
    "The file "basename$_FILES['site1']['name']). " has been uploaded";
     } 
    ?>
    <input name="site_url" type="hidden" class="input" value="<?php echo basename$_FILES['site1']['name']); ?>" />
    But it's not working. Any thoughts?


  •  

    Posting Permissions

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