PHP Problem...

RWBRWB Icrontian
edited December 2006 in Internet & Media
[PHP]<?php

if ( move_uploaded_file ($_FILES ,
"../uploads/{$_FILES }") )
{ print '<p> The file has been successfully uploaded </p>';
}
else
{
switch ($_FILES )
{ case 1:
print '<p> The file is bigger than this PHP installation allows</p>';
break;
case 2:
print '<p> The file is bigger than this form allows</p>';
break;
case 3:
print '<p> Only part of the file was uploaded</p>';
break;
case 4:
print '<p> No file was uploaded</p>';
break;
}
}

?>[/PHP]

Creating a simple upload form, an html file is posting to the getfile.php page, but the file doesn't upload and it doesn't give me an error report.

It comes from this tutorial I am working on BTW.
http://www.htmlgoodies.com/beyond/php/article.php/3472561

I am also not entirely sure how the switch/case function works... I figured I might be able to tell if it gave me an error, but it does nothing... not even if I take it out and use a simple print statement for "else".

Comments

  • ShortyShorty Manchester, UK Icrontian
    edited December 2006
    Turn on your error reporting option in php.ini and you will get an error, which will help you figure out the problem :)
  • RWBRWB Icrontian
    edited December 2006
    This is actually on some web space(sarcnet), so I don't think I have access to that info :(
  • ShortyShorty Manchester, UK Icrontian
    edited December 2006
    Put this after your < ?php ....

    ini_set('error_reporting', E_ALL);

    That will turn it on .. on a per script basis ;)
  • LincLinc Owner Detroit Icrontian
    edited December 2006
    Kill the spaces between the array elements.
    This:[php]$_FILES[/php]
    Instead of this:[php]$_FILES [/php]

    I don't know if that's what's screwing it up, but I've never seen the syntax written with that space.
  • LincLinc Owner Detroit Icrontian
    edited December 2006
    btw, a default case might've helped a little too.

    [php]default: echo "<p>I don't know, this is what you sent me: ".$_FILES."</p>";
    break;[/php]
    You could try that with and without the space and see what happens... I imagine it will do something funky with the space, and without it the whole shebang will either work or you'll at least see what's in the error field :)
  • RWBRWB Icrontian
    edited December 2006
    I am just lost in this...

    putfile.htm
    [PHP]<html>
    <head>
    <title>File Upload Form</title>
    </head>
    <body>
    This form allows you to upload a file to the server.<br>

    <form action="getfile.php" method="post"><br>
    Type (or select) Filename: <input type="file" name="uploadFile">
    <input type="hidden" name="MAX_FILE_SIZE" value="25000" />
    <input type="submit" value="Upload File">
    </form>

    </body>
    </html>[/PHP]

    getfile.php
    [PHP]<html>
    <head>
    <title>Process Uploaded File</title>
    </head>
    <body>

    <?php

    if ( move_uploaded_file ($_FILES ,
    "../uploads/{$_FILES }") )
    { print '<p> The file has been successfully uploaded </p>';
    }
    else
    {
    switch ($_FILES )
    { default: echo "<p>I don't know, this is what you sent me: ".$_FILES ."</p>";
    break;

    case 1:
    print '<p> The file is bigger than this PHP installation allows</p>';
    break;
    case 2:
    print '<p> The file is bigger than this form allows</p>';
    break;
    case 3:
    print '<p> Only part of the file was uploaded</p>';
    break;
    case 4:
    print '<p> No file was uploaded</p>';
    break;
    }
    }

    ?>
    </body>
    </html>[/PHP]

    I've removed the spaces between all the brackets as well, like so...

    getfile.php modified
    [PHP]<html>
    <head>
    <title>Process Uploaded File</title>
    </head>
    <body>

    <?php

    if ( move_uploaded_file ($_FILES,
    "../uploads/{$_FILES}") )
    { print '<p> The file has been successfully uploaded </p>';
    }
    else
    {
    switch ($_FILES)
    { default: echo "<p>I don't know, this is what you sent me: ".$_FILES."</p>";
    break;

    case 1:
    print '<p> The file is bigger than this PHP installation allows</p>';
    break;
    case 2:
    print '<p> The file is bigger than this form allows</p>';
    break;
    case 3:
    print '<p> Only part of the file was uploaded</p>';
    break;
    case 4:
    print '<p> No file was uploaded</p>';
    break;
    }
    }

    ?>
    </body>
    </html>[/PHP]

    I kind of feel that I messed up maybe in the putfile.htm page, somewhere... somehow... but I don't see it! lol
  • LincLinc Owner Detroit Icrontian
    edited December 2006
    Ah ha. Your form is not equipped to handle a file without setting the enctype:
    [php]<form action="getfile.php" method="post" enctype="multipart/form-data">[/php]
  • RWBRWB Icrontian
    edited December 2006
    Sweet! Now I am getting somewhere... but I get this message:
    Warning: move_uploaded_file(../uploads/database.txt) [function.move-uploaded-file]: failed to open stream: Permission denied in /var/www/vhosts/fusion-dm.net/httpdocs/test/getfile.php on line 10

    Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/php0OFqnJ' to '../uploads/database.txt' in /var/www/vhosts/fusion-dm.net/httpdocs/test/getfile.php on line 10

    I don't know, this is what you sent me: database.txt
  • RWBRWB Icrontian
    edited December 2006
    I've been thinking, could it be an incompatibility type of issue? I think these tutorials are written for PHP4.3 and I am now on PHP5. Possible fix?

    I think I am gonna move on to some newer tutorials I have found, retrace my steps and learn more. These seem nice:
    http://devzone.zend.com/node/view/id/627
  • Park_7677Park_7677 Missouri Member
    edited December 2006
    Check your permissions on the server for that path. Make sure the "world" or "others" can write to it.
  • LincLinc Owner Detroit Icrontian
    edited December 2006
    Sorry I forgot to check back; Park's got it :) Sounds like your upload folder can't be written to.
  • RWBRWB Icrontian
    edited December 2006
    Thanks guys, I'll check into that.

    Sweet, it works now!!! Thanks.
Sign In or Register to comment.