SitePoint Sponsor

User Tag List

Results 1 to 19 of 19
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    Canada
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    I need help with creating a form that uploads files to my server!!

    Hey, I have Apache 1.3.33 running on my windows XP Operating System.

    I have created 2 pages, 1 with the form used to upload the file, and another page that is used to process the file.

    When i test it out, the form works fine, but the second page says:

    Method Not Allowed
    The requested method POST is not allowed for the URL /savefile.php.


    Heres the code for both pages:

    Page with form used to upload file:
    Code:
    <html>
    <head>
    <title>File Storage</title>
    </head>
    <body>
    Use the form below to upload a file to our server!
    <p>
    <form action="savefile.php" enctype="multipart/form-data" method="post">
    
    File name:
    <input type="file" name="uploadedFile">
    <p>
    <input type="submit" value="Upload">
    </form>
    
    </body>
    </html>

    Page used to process the file:
    Code:
    <html>
    <head>
    <title>Processing your uploaded file...(pending)</title>
    </head>
    <body>
    
    <?php
    
    if ($HTTP_POST_FILES['uploadedFile']['size'] <= 0)
    {
    	print "<b><font color="red">A error has occured: File size is to large.</font></b><br>";
    	print "The maximum file size is: <b>2500KB<b><br>";
    }
    eles	
    {
    	copy($HTTP_POST_FILES['uploadedFile']['tmp_name'],
    		$HTTP_POST_FILES['uploadedFile']['name']);
    	print "<b><font color="green">Your file has been succesfully uploaded!</font></b>";
    }
    
    ?>
    
    </body>
    </html>
    Can anyone please help me?

  2. #2
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    This function:
    $HTTP_POST_FILES
    is deprecated and I think won't work now,
    change it to
    $_FILES and see if it makes a difference
    PHP Code:
    <html>
    <head>
    <title>Processing your uploaded file...(pending)</title>
    </head>
    <body>

    <?php

    if ($_FILES['uploadedFile']['size'] <= 0)
    {
        print 
    "<b><font color=\"red\">A error has occured: File size is to large.</font></b><br>";
        print 
    "The maximum file size is: <b>2500KB<b><br>";
    }
    eles    
    {
        
    copy($_FILES['uploadedFile']['tmp_name'],
            
    $_FILES['uploadedFile']['name']);
        print 
    "<b><font color=\"green\">Your file has been succesfully uploaded!</font></b>";
    }

    ?>

    </body>
    </html>
    EDIT: you will also get some parse errors as you haven't escaped thequotes around your colour definitions.
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  3. #3
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    Canada
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    k, well i did what you said, but im still getting the error.

    Thx anywayz tho!

  4. #4
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    OK, looking through your code, I don't think that it would work as expected as you are missing a few key components (where to upload to etc)
    Try this script (all one page)
    PHP Code:
    <? 

        
    //Check that submit has been pressed 
        
    if($_POST['submit']){ 
        
    $message '';
            
    // directory Path edit with your own 
            
    $uploaddir 'upload/'
             
                 
                
    // Upload data 
                
    $tempname $_FILES['userfile']['tmp_name'];
                
    $filename $_FILES['userfile']['name'];
                
    // Move file 
                
    if($tempname != ''){ 
                    
    move_uploaded_file($tempname$uploaddir.$filename); 
                    
    $message .= 'the file '$filename .' has been uploaded <br>';
            } 
        } 
    ?> 

    <html> 
        <head> 
            <title>File Upload</title> 
        </head> 
        <body> 

        <form enctype="multipart/form-data" action="" method="POST"> 
            <input name="userfile" type="file"><br /> 
            <input type="submit" name="submit" value="Upload"> 
        </form> 
    <? if(isset($message) && ($message != '')) { echo $message; } ?>
        </body> 
    </html>
    Mike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  5. #5
    SitePoint Evangelist klik's Avatar
    Join Date
    Jan 2005
    Location
    Scotland, UK
    Posts
    547
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Spikez, had an 'eles' in the code.

    Be sure to change this to 'else'

  6. #6
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    Canada
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Its still giving me that error. i tried your code. Somthing is still wronge... :S

  7. #7
    SitePoint Evangelist klik's Avatar
    Join Date
    Jan 2005
    Location
    Scotland, UK
    Posts
    547
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try using an absolute URL for your upload directory.

  8. #8
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    Canada
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    heh, well im reading this out of a book. It says that i dont need a directory, it says that the files will just be uploaded where the php file is...

    :S

  9. #9
    SitePoint Evangelist klik's Avatar
    Join Date
    Jan 2005
    Location
    Scotland, UK
    Posts
    547
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Post your entire code here, that you're using. I'm not sure which code you're using.

  10. #10
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    Canada
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Page with the upload file form:

    PHP Code:
    <html
    <
    head
    <
    title>File Upload</title
    </
    head
    <
    body
    Use 
    the form below to upload a file to our server
    <p>

    <
    form action="savefile.php" enctype="multipart/form-data" method="post">
    <
    p>
    Enter File Name:
    <
    input type="file" name="uploadedFile">
    <
    p>
    <
    input type="submit" value="Upload">
    </
    form>

    </
    body
    </
    html
    Page which processes the file:
    PHP Code:
    <html> 
    <head> 
    <title>Processing your uploaded file...(pending)</title> 
    </head> 
    <body> 

    <?php 

    if ($_FILES['uploadedFile']['size'] <= 0
    {
        print 
    "<b><font color='red'>A error has occured: File size is to large.</font></b><br>"
        print 
    "The maximum file size is: <b>2500KB<b><br>"

    else     

        
    copy($_FILES['uploadedFile']['tmp_name'], 
            
    $_FILES['uploadedFile']['name']); 
        print 
    "<b><font color='green'>Your file has been succesfully uploaded!</font></b>"


    ?> 

    </body> 
    </html>

  11. #11
    SitePoint Evangelist klik's Avatar
    Join Date
    Jan 2005
    Location
    Scotland, UK
    Posts
    547
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    <html>
    <head>
    <title>Processing your uploaded file...(pending)</title>
    </head>
    <body>

    <?php

    if ($_FILES['uploadedFile']['size'] <= 0)
    {
        print 
    "<b><font color='red'>A error has occured: File size is to large.</font></b><br>";
        print 
    "The maximum file size is: <b>2500KB<b><br>";
    }
    else     
    {

    /* Manage file Upload */

            
    $uploadDir '/home/username/public_html/images/test'// change this to specify a premade directory which is chmoded 777


            
    if(is_uploaded_file($_FILES['uploadedFile']['tmp_name'])){
                
    move_uploaded_file($_FILES['uploadedFile']['tmp_name'],$uploadDir.'/'.$_FILES['uploadedFile']['name']);
            }

        
    /* END Manage file upload */

        
    print "<b><font color='green'>Your file has been succesfully uploaded!</font></b>";
    }

    ?>

    </body>
    </html>
    Not tested. Also, make sure it's called savefile.php

  12. #12
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    Canada
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Its still not working... But could it have somthing to do with the permissions or somthing...

    Maybe I havent gaving it permission to use "POST"?

    I havent played around with any CHMOD's or w/e....

  13. #13
    SitePoint Evangelist klik's Avatar
    Join Date
    Jan 2005
    Location
    Scotland, UK
    Posts
    547
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have to allow read/write/execute permissions on the folder you're uploading to. Most FTP programs will offer this. Set it to tick all boxes or to 777 depending on program. The directory needs to be alreadycreated and file permissions set, before this code can function.

  14. #14
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    Canada
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hrm, well i dont have a FTP at all. I think i need to set up a FTP server, and get a ftp program before i can do this dont I?

    Damn... k, ill go do that now.

  15. #15
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    Canada
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Method Not Allowed
    The requested method POST is not allowed for the URL /savefile.php.

    Still giving me that error... I set up a FTP server, and got a FTP program and CHMODed everything to 777 it still doesnt work.


  16. #16
    dooby dooby doo silver trophybronze trophy
    spikeZ's Avatar
    Join Date
    Aug 2004
    Location
    Manchester UK
    Posts
    13,804
    Mentioned
    157 Post(s)
    Tagged
    3 Thread(s)
    Something occurred to me last night, there is nothing wrong with the above scripts it might be that your hosts haven't enabled the POST option on your account (that is if you are using a host!)

    Mike
    Mike Swiffin - Community Team Advisor
    Only a woman can read between the lines of a one word answer.....

  17. #17
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    Canada
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yeah, lol. Thats whats wronge...

    I have a server which i pay for... I tried the scripts out on that, and it worked fine.

    But on my OWN server which i made myself... it doesnt work. I have the CHMOD set to 777 on ALL files... So i know thats not the issue. Im guessing it has somthing to do with the httpd.conf file.

    I probably have to edit somthing to enable POST, but i dont know how... or what to edit.

    I made a post in the apache form, hopefully somone there can help me.

    Regards,

    X-Factor

  18. #18
    SitePoint Evangelist klik's Avatar
    Join Date
    Jan 2005
    Location
    Scotland, UK
    Posts
    547
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    In your php.ini file try adding 'P' to variables_order if it isn't already there. This isn't my strong field, so back up before trying it. Good luck getting it to work!

  19. #19
    SitePoint Enthusiast
    Join Date
    Dec 2004
    Location
    Canada
    Posts
    53
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hrm, well im gonna try starting from scratch again... Possibly i did somthing wronge along the way...

    Iuno if i setup PHP and installed it correctly.

    Do either of you have MSN? If so, could you maybe PM me your address?

    Regards,
    XF


Bookmarks

Posting Permissions

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