0

I cant seem to upload a file in php to my server from just anywhere, it will only upload correctly if the file is in the same folder as my upload script which is a serious problem if i want the user to be able to upload from just anywhere.

here is my full code:

require ('dbconnect.php'); // connect to database

// initial database stuff
    set_time_limit(0);
    ini_set('memory_limit', '1024M');

    $file = $_FILES["file"]["name"];
    $file_handle = fopen($file, "r");

    $count= 1;
    mysql_query("TRUNCATE TABLE numdata") or die("MySQL Error: " . mysql_error()); //Delete the existing rows

    while (($data = fgetcsv($file_handle, 0, ",")) !== FALSE)
    {
        foreach($data as $row)
        {
            if($count % 2)
            {
                $complete = $row;
            }
            else{
                $complete .= $row;
                $insertArray[] = $complete;
            }
        $count++;
        $query="INSERT INTO numdata(numb) values($complete)";
        }
        mysql_query($query) or die(mysql_error());
    }

fclose($file_handle);

how do i change the code to enable uploads from any location, or is there a setting i need to change for my server? Any help is greatly appreciated!

Thanks for your time and wisdom.

2
Contributors
3
Replies
21
Views
3 Years
Discussion Span
Last Post by berserk
0

How are you posting to the script? You need to upload the file and move the file to upload dir or temp dir.. The add the path and file name to fgetcsv.

fgetcsv('path/filename.csv')

0

is there an example i can use for uploading the file then saving it to a location an dusing it from that location? and also deleteing it for storage purposes

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.