I have this script that will NOT work no matter what i add to it, i have fopen not working and i believe that is the root of all my other errors but i cannot be sure, i originally had 8 errors but 4 of them were simple notices for undefined variables. I want to make my code work cross platform because I feel my program should be freely used on multiple platoforms, be it mac os, windows, or linux (preferably linux), any help would be greatly appreciated. Here are the errors and code below.
errors
Warning: fopen(/uploaded/606.txt): failed to open stream: No such file or directory in /opt/lampp/htdocs/upload/newup.php on line 19
Warning: fgetcsv() expects parameter 1 to be resource, boolean given in /opt/lampp/htdocs/upload/newup.php on line 24
Warning: Invalid argument supplied for foreach() in /opt/lampp/htdocs/upload/newup.php on line 26
Notice: Undefined variable: query in /opt/lampp/htdocs/upload/newup.php on line 39
Query was empty
and here is the code im working with.
<?php
ini_set('session.save_path', '/opt/lampp/htdocs/tmp');;
session_start();
require ('dbconnect.php'); // connect to database
// initial database stuff
set_time_limit(0);
ini_set('memory_limit', '1024M');
$file = NULL;
// Where the file is going to be placed
$target_path = "/uploaded/";
/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$file = $file.basename($_FILES['file']['name']);
$file_handle = fopen($target_path.$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);
also forgot to mention that i have this script working FLAWLESSLY on windows, so yeah :/