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 8411989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T00:33:52+00:00 2026-06-10T00:33:52+00:00

I have a PHP script that uploads a CSV file and then saves some

  • 0

I have a PHP script that uploads a CSV file and then saves some of the contents of the csv file to a database. Everything on the script works fine when I use a file that is about 40 kb, about 100 lines. But when I try to upload a similar structured file that is 850 kb and larger, I get this error message:

Array ( [type] => 2048 [message] => Only variables should be assigned
by reference [file] => /home/dir_name/uploader.php [line] => 10 )

Which is output from the error_get_last() function.

Here is the script I am using:

<?php

/*
 * Config
 */

mysql_connect(/* creds */) or die(mysql_error());
mysql_select_db('db_name');

$user =& JFactory::getUser();
$user_id = $user->get('id');

ini_set('error_log','/home/dir_name/error.log');
ini_set('upload_max_filesize', '50M');
ini_set('memory_limit','32M');
ini_set('post_max_size','32M');


/*
 * Upload CSV File
 */

if (isset($_FILES['uploadedfile'])){
    if (substr($_FILES['uploadedfile']['name'],-3,3) == "csv"){
        echo $_FILES['uploadedfile']['name']."<br/>";
        $thefile = fopen($_FILES['uploadedfile']['tmp_name'],'r');
        if ($thefile === false){
            print_r(error_get_last());
            exit;
        }
        while (($data = fgetcsv($thefile, 0, ";",'"')) !== FALSE) {
            if($data[0] == "Item Number"){
                continue;
            }
            /*
             * Do all the stuff to data and save to db
             */
            ...
            ...
        }
        //header("Location: ".$_SERVER['PHP_SELF']);
    }
}

?>
<form enctype="multipart/form-data" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="100000" />
    Choose your CSV file of inventory: <input name="uploadedfile" type="file" />
    <input type="submit" value="Upload File" />
</form>

As you can see I have manually set the upload_max_filesize, memory_limit, and post_max_size variables because I thought that might be the problem… but it didn’t seem to change anything. Any help with this problem would be greatly appreciated. I want to be able to upload BIG files with this script. 🙂

** EDIT **

Remember that this script works well when the file was small enough. I tried it again with a small file (100 lines), and its good. I removed the & from 10th line, and now I get this error when trying a bigger file:

Array ( [type] => 2048 [message] => Only variables should be assigned
by reference [file] =>
/home/dir_name/plugins/content/jw_simpleImageGallery/jw_simpleImageGallery.php
[line] => 32 )

This error is being thrown by the function error_get_last on line 28, which means that the fopen function returned FALSE. It is definitely a problem with opening the uploaded file. For some reason the error_get_last function is showing errors (I think they are warnings) that don’t have to do with the file upload.

** EDIT 2 **

I checked the vales of the PHP ini variables like this:

ini_set('error_log','/home/pkind2/tim/error.log');
ini_set('upload_max_filesize', '50M');
ini_set('memory_limit','32M');
ini_set('post_max_size','32M');
echo ini_get('upload_max_filesize').'<br>';
echo ini_get('memory_limit').'<br>';
echo ini_get('post_max_size').'<br>';

and the output is:

100 M
50 M
100 M

I guess I do not have the privileges to change these variables, but by default they are set very high already, so it doesn’t look like these variables are getting in the way of an 850 k file.

** EDIT 3 **

I checked the value of $_FILES['uploadedfile']['tmp_name'], and for the small fiel ( ~ 37 kb ) I get this output:

/tmp/php7yto3f

But when I try the 850 KB file it doesn’t output anything for that variable, and then I get the crash. SO it seems that the file isn’t being saved to the temporary location for the bigger file size.

** EDIT 4 **

The problem turned out to be the <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> That must by 100,000 bytes, or 100 kb, so i increased this value and the bigger file worked… :-/

  • 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-10T00:33:53+00:00Added an answer on June 10, 2026 at 12:33 am

    I think the problem is on line 10:

    $user =& JFactory::getUser();
    

    Try to remove the “&”.

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

Sidebar

Related Questions

I have a PHP script that receives uploads and it works fine in mamp,
I have a PHP script that processes file uploads. The script tries to organise
I have a script that uploads a file and then moves it to a
I have a php script that watches for the newest json file in a
I have a PHP script that executes a .bat file using system(cmd /c C:\dir\file.bat);
My PHP script that uploads a file, cannot do so in directories at a
I have a simple swf file upload script that uploads a file as soon
I have an upload PHP script and before it uploads the file, it renames
I have a php-script that uploads files to an ftp server from a location
I have a .csv file that I need to upload to the database. There

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.