Not signed in (Sign In)

SkillShare - A place to discuss Web Standards and Web Design topics

Categories

Vanilla 1.1.9 is a product of Lussumo. More Information: Documentation, Community Support.

    • CommentAuthoropel
    • CommentTimeSep 7th 2007
     permalink
    Hello,

    I have been working on a script to upload mp3, doc, and pdf files and put them on a folder on my server usin PHP. I have tried writing 3 different scripts all seem to be failing through the if option statements. Can anyone tell me where I am going wrong please ? Code is below :


    <?php

    require_once('includes/inc_functions.php');
    $target = "../files/";

    if(isset($_POST['Submit'])) {
    //reads the name of the file the user submitted for uploading
    $file=$_FILES['file']['name'];
    // if it is not empty
    if ($file)
    {
    // get the original name of the file from the clients machine
    $filename = stripslashes($_FILES['file']['name']);



    // get the extension of the file in a lower case format
    $extension = getExtension($filename);
    $extension = strtolower($extension);
    // if it is not a known extension, we will suppose it is an error, print an error
    //message
    //and will not upload the file, otherwise we continue
    if (($extension != "doc") && ($extension != "jpg") && ($extension != "pdf"))
    {
    echo '<h1>Unknown extension!</h1>';
    $errors=1;
    }
    else
    { // put files in folder

    $target_path = "../files/";

    $target_path = $target_path . basename( $_FILES['file']['name']);

    if(move_uploaded_file($_FILES['file']['tmp_name'], $target_path)) {

    echo "<h1>It works, $file uploaded !</h1>";

    }

    else {
    echo "<h1>There is a problem</h1>";
    }
    }
    }
    }
    else {

    ?>




    <body>

    <form name="newad" method="post" enctype="multipart/form-data" action=""><input type="hidden" name="phpMyAdmin" value="4594f30712f4fabaff6997416810f3f2" />
    <table width="300" align="center" id="uploadImg">
    <tr>
    <td colspan="2"><h1>Upload Files</h1></td>
    </tr>
    <tr>
    <td colspan="2"> <p align="center" style="font-size:10px;">You can upload files with the <strong>.MP3, doc and pdf </strong> extension using this form. Please make sure that all your MP3's have been ID3 tags or they will not display in the flash player.</p></td>
    </tr>
    <tr>
    <td>Please choose a file :</td>
    <td><input name="file" type="file" /></td>
    </tr>
    <tr>
    <td colspan="2"><div align="center">
    <input type="submit" value="Upload File" name="Submit" />
    </div></td>
    </tr>
    <tr>
    <td colspan="2"><div align="center"><a href="javascript:window.close()" title="Close Window">Close Window</a></div></td>
    </tr>
    </table>

    </form>
    </div>

    </body>
    </html><?
    } // end else
    ?>
    • CommentAuthoreasement
    • CommentTimeSep 7th 2007
     permalink
    Does the file actually make it to the server or are you having trouble moving it once it is on the server?

    What do you get when you issue:

    echo "<pre">
    print_r($_FILES);
    echo "</pre>";


    I use Easy PHP Upload and it works like a champ.
    http://www.finalwebsites.com/snippets.php?id=7
    • CommentAuthoropel
    • CommentTimeOct 10th 2007
     permalink
    I managed to get it working but have bookmarked that link thanks.
Add your comments
    Username Password
  • Format comments as (Help)