SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict mr.pita's Avatar
    Join Date
    Aug 2005
    Location
    USA
    Posts
    303
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Works in PHP 4 but not PHP 5

    I have the following code to upload files:

    PHP Code:
    $new_file_name something.jpg;


    $path"../files/".$new_file_name;
    if(
    $ufile !=none)
    {
    if(
    copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
    {
    echo 
    "Uploaded file ".$new_file_name." successfully<br>";
    }
    else
    {
    echo 
    "Something went wrong";
    die();
    }

    This code works fine in PHP 4.4.7 but it gives the 'something went wrong' error message in 5.2.2. Anyone know why?

  2. #2
    SitePoint Wizard cranial-bore's Avatar
    Join Date
    Jan 2002
    Location
    Australia
    Posts
    2,634
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Turn error reporting on (display errors). Search the manual for details.

    Looks like $ufile should be coming from the form? If so it won't be automatically created because register globals are off by default in PHP5 (and PHP4 for some time as well).
    Try accessing $_POST['ufile'] instead.

    This is probably another error
    PHP Code:
    if($ufile != none
    Unless none is a defined constant this will generate an error. I assume you mean the string 'none' (with quotes).

    And I'm not sure if $HTTP_POST_FILES is fully deprecated yet, but it will be if not already.
    Use $_GET, $_POST, $_COOKIE, and $_FILES instead.

    To get a more useful error message check $_FILES['ufile']['error']
    The error codes are explained here.

  3. #3
    rajug.replace('Raju Gautam'); bronze trophy Raju Gautam's Avatar
    Join Date
    Oct 2006
    Location
    Kathmandu, Nepal
    Posts
    4,013
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes go for like this:
    PHP Code:
    $new_file_name "something.jpg";
    $path "../files/".$new_file_name;
    //if($ufile != "none"){
    if(is_uploaded_file($_FILES['ufile']['tmp_name'])){
        
    //if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path)){
        
    if(copy($_FILES['ufile']['tmp_name'], $path)){
            echo 
    "Uploaded file ".$new_file_name." successfully<br>";
        }
        else{
            echo 
    "Something went wrong";
            die();
        }

    Mistakes are proof that you are trying.....
    ------------------------------------------------------------------------
    PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5

  4. #4
    SitePoint Addict mr.pita's Avatar
    Join Date
    Aug 2005
    Location
    USA
    Posts
    303
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks guys, got it working.


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
  •