Register

If this is your first visit, please click the Sign Up now button to begin the process of creating your account so you can begin posting on our forums! The Sign Up process will only take up about a minute of two of your time.

Results 1 to 5 of 5

Thread: uploading files

  1. #1
    Senior Member jf1288's Avatar
    Join Date
    Sep 2003
    Posts
    215
    Member #
    3300
    I've tried a few different scripts, with no success. Is there someplace i can find a working upload script? Thanks
    If its not in Family Guy its not worth it.

  2.  

  3. #2
    Senior Member skrlin's Avatar
    Join Date
    Apr 2003
    Location
    Illinois
    Posts
    562
    Member #
    1063
    Here is what my working script looks like:
    file.htm
    PHP Code:
    <h1 style="color:RED">Upload A File</h1><HR>
    <
    form action="upload.php" method="post" enctype="multipart/form-data">
    Upload a file: <input type="file" name="theFile"><BR><BR>
    <
    input type="submit" value="submit" name="submit">
    </
    form
    upload.php
    PHP Code:
    <?php
        $aErrors 
    "";
        if ( !empty( 
    $theFile_name ) ) // no file selected
        
    {
            if ( 
    $theFile_size < ( 1024 1000 ) )
            {
               
    $aCurBasePath dirname$PATH_TRANSLATED );
               
    $aNewName $aCurBasePath "/uppics/" $theFile_name;
               
    copy$theFile$aNewName );
            } else {
               
    $aErrors .= "The File was too big";
            }
        } else {
           
    $aErrors "No file selected";
        }
    ?>
    <html>
    <head>
    <title>Uploaded Image</title>
    </head>
    <body>

    <?php
        
    if ( $aErrors != "" )
        {
           print( 
    "<B>There were errors</b>: $aErrors<BR>" );
        } else {
           print( 
    "The picture you uploaded:<BR><BR>" );
           print( 
    "<img src=\"uppics/$theFile_name\" border=\"0\"><BR>" );
           print( 
    "<a href=\"/other/uppics/$theFile_name\">/other/uppics/$theFile_name</a>" );
        }
    ?>
    </body>
    </html>
    It was originally only for images of type jpeg, png, gif but I modified it to accept anything under 1mb in size. Feel free to play with the code if you like
    - Brian

  4. #3
    Senior Member jf1288's Avatar
    Join Date
    Sep 2003
    Posts
    215
    Member #
    3300
    awsome thanks
    If its not in Family Guy its not worth it.

  5. #4
    Member Seraph's Avatar
    Join Date
    Sep 2003
    Posts
    81
    Member #
    3090
    I would like to warn you that this will only work on servers with register_globals on. to use it with register globals off
    I suggest you read more on this page
    http://us2.php.net/manual/en/features.file-upload.php

    but to use his script with globals off you must replace
    $theFile_ With $_FILES['theFile'][' then add '] at the end of the variable
    at cases like
    "uppics/$theFile_name\"
    you must put the whole variable in brackets {}

  6. #5
    Senior Member jf1288's Avatar
    Join Date
    Sep 2003
    Posts
    215
    Member #
    3300
    well i guess i dont have globals on because the script that i had gotten to work used the $_FILE variable. heres what i ended up with:
    PHP Code:
    // Uploading large picture
    $name $HTTP_POST_FILES['large']['name'];
    $type substr($name,-4,4);
    $largeName $_POST['picture'].$type;


        
    $aErrors "";
        if ( !empty( 
    $HTTP_POST_FILES['large']['name'] ) ) // no file selected
        
    {
            if ( 
    $HTTP_POST_FILES['large']['size'] < ( 1024 1000 ) )
            {
               
    $aCurBasePath dirname$PATH_TRANSLATED );
               
    $aNewName $aCurBasePath "/large/" $largeName;
               
    copy$HTTP_POST_FILES['large']['tmp_name'], $aNewName );
            } else {
               
    $aErrors .= "The File was too big";
            }
        } else {
           
    $aErrors "No file selected";
        }

        if ( 
    $aErrors != "" )
        {
           print( 
    "<B>There were errors uploading the large image</b>: $aErrors<BR>" );
        } else {
           print( 
    "The large picture you uploaded:<BR><BR>" );
           print( 
    "<img src=\"large/".$largeName."\" border=\"0\"><BR>" );
        }


    // Uploading small picture
    $name $HTTP_POST_FILES['small']['name'];
    $type substr($name,-4,4);
    $smallName $_POST['picture'].$type;


        
    $aErrors "";
        if ( !empty( 
    $HTTP_POST_FILES['small'] ) ) // no file selected
        
    {
            if (
    $HTTP_POST_FILES['small']['size'] < ( 1024 1000 ) )
            {
               
    $aCurBasePath dirname$PATH_TRANSLATED );
               
    $aNewName $aCurBasePath "/small/" $smallName;
               
    copy$HTTP_POST_FILES['small']['tmp_name'], $aNewName );
            } else {
               
    $aErrors .= "The File was too big";
            }
        } else {
           
    $aErrors "No file selected";
        }

        if ( 
    $aErrors != "" )
        {
           print( 
    "<B>There were errors uploading the thumbnail</b>: $aErrors<BR>" );
        } else {
           print( 
    "The thumbnail you uploaded:<BR><BR>" );
           print( 
    "<img src=\"small/".$smallName."\" border=\"0\"><BR>" );
        }
                
    // Error checking
    if (isset($error) || $aErrors <> "") {
        die(
    "encountered errors");




    Thanks for the help to everyone who gave me tips
    If its not in Family Guy its not worth it.


Remove Ads

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
All times are GMT -6. The time now is 10:10 AM.
Powered by vBulletin® Version 4.2.3
Copyright © 2019 vBulletin Solutions, Inc. All rights reserved.
vBulletin Skin By: PurevB.com