Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8441543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T08:35:15+00:00 2026-06-10T08:35:15+00:00

I don’t really know much PHP. But anyways I am not able to upload

  • 0

I don’t really know much PHP. But anyways I am not able to upload a .csv file using the following php. I have fixed the problem with upload_max size related attributes. Works fine on my local but not on sandbox. Is it file type problem?

I can only get it to print something like this… which is not helpful at all.
“– CSV file to load: >>> NOT a file valid: 1 “

where should I fix? How do I print a complete PHP error message instead of just the value “1” which I’m not sure what it corresponds to? ie… output more useful print like this “UPLOAD_ERR_INI_SIZE: 1”?

<?php
// using upload at click from http://code.google.com/p/upload-at-click/
// FileData is the name for the input file

$file_result = "";
$file = $_FILES['Filedata'];

$allowedExtensions = array("csv", "txt");
$arrayVar = explode(".", $file["name"]);
$extension = end($arrayVar);

//commented out for “Only variables should be passed by reference” error
//$extension = end(explode(".", $file["name"]));


function isAllowedExtension($fileName) {
    global $allowedExtensions;
    return in_array(end(explode(".", $fileName)), $allowedExtensions);
}

if($file["error"] > 0){
    echo "failure to upload the file >>> ". "Error code: ".$file["error"]."<br>";
}else{
    //echo " >>> CURRENT DIR: ".getcwd() . "\n";
    $workDir = getcwd();

    $dir = substr($workDir, 0, -10);
    $path = $file["name"];
    $newFileLoc = $dir.$path;

    $file_result.=
    "<br>     Upload: " . $file["name"] . "<br>" .
    "     Type: " . $file["type"] . "<br>" .
    "     Size: " . $file["size"] . "<br>" .
    "     file uploaded to: ".$newFileLoc."<br>";

    // txt - text/plain
    // rtf - application/msword
    // dat/obj - application/octet-stream
    // csv - application/vnd.ms-excel
    // maximum 200 MB file - 200,000,000 k

    if (    ($file["type"] == "application/vnd.ms-excel" || $file["type"] == "text/plain")
            && isAllowedExtension($file["name"])
            && ($file["size"] < 200000000)
        )
        {   
            move_uploaded_file($file["tmp_name"], $newFileLoc);
            //echo $file_result.=" >>> File uploaded successfull!!";
            echo "|".$path;//"filePath : " . $newFileLoc;

        }else{
            echo " >>> NOT a file valid: ". isAllowedExtension($file["name"]);
        }       
}
?>

This is the line that was added as suggested by another user to catch the error correctly. Please let me know if that’s right sorry i don’t know much PHP at all. Anyways, the error printed is just “– CSV file to load: >>> NOT a file valid: 1 “

<?php
// using upload at click from http://code.google.com/p/upload-at-click/
// FileData is the name for the input file

ini_set('display_errors', 1); error_reporting(E_ALL);

$file_result = "";
$file = $_FILES['Filedata'];

$allowedExtensions = array("csv", "txt");
$arrayVar = explode(".", $file["name"]);
$extension = end($arrayVar);
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T08:35:17+00:00Added an answer on June 10, 2026 at 8:35 am

    The block in question is the following:

    if( ( $file["type"] == "application/vnd.ms-excel" || $file["type"] == "text/plain" ) && 
        isAllowedExtension($file["name"]) && 
        ( $file["size"] < 200000000 ) )
    {   
        move_uploaded_file($file["tmp_name"], $newFileLoc);
    
        //echo $file_result.=" >>> File uploaded successfull!!";
    
        echo "|".$path;//"filePath : " . $newFileLoc;
    }
    else
    {
        echo " >>> NOT a file valid: ". isAllowedExtension($file["name"]);
    }
    

    Note that you’re hitting your else echo, and the ‘1’ is because isAllowedExtension() is returning a boolean, which is true, which is denoted as ‘1’ (as opposed to ‘0’) when you print it.

    One of your conditions in the if there are failing. I’d separate them out a bit, and see which in particular is.

    EDIT For example:

    if( ( $file["type"] == "application/vnd.ms-excel" || $file["type"] == "text/plain" ) )
    {
        if( isAllowedExtension($file["name"]) )
        {
            if( $file["size"] < 200000000 )
            {
                move_uploaded_file($file["tmp_name"], $newFileLoc);
    
                echo "|".$path;//"filePath : " . $newFileLoc;
            }
            else
            {
                echo "Invalid file size: " . $file["size"] . "\n";   
            }
        }
        else
        {
            echo "Invalid extension: " . $file["name"] . "\n";   
        }    
    }
    else
    {
        echo "Invalid type: " . $file["type"] . "\n";
    }
    

    Alternatively, you can just print_r() $file and see what it’s values are.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Don't know if I'm over-thinking this or not.. but I'm trying to be able
Don't really know how to formulate the title, but it should be pretty obvious
Don't know why but font is not displaying.Please help. CSS(in css folder): style.css: @font-face
I don't know if this question is trivial or not. But after a couple
Don't know why this is happening, but after submitting a form via JS (using
don't know if the title describes anything about what I'm trying to say but
Don't know how to google for such, but is there a way to query
Don't ask me why but I need to do the following: string ClassName =
I don't know why, but this code worked for me a month ago... maybe
Don't know if I worded the question right, but basically what I want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.