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.

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')

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

i got it figured out

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.