I have a flat file of items for a web mall. I have uploaded and read the file in php. I then figured out what ofset I needed for the categories. The listing was stored like this...
Level1|level|level3| Etc.
the data supplier used the pipe for a subcategory separator. here is the code i am using to explode the data into separate categories so I can set up the subcategories in the cart database....
@$file = $_POST['userfile'];
//$uploaddir = "C:/Temp/";
$uploaddir = 'C:\\Apache2\\htdocs\\shopscript\\importer\\tmp\\';
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']);
$file = basename($_FILES['userfile']['name']);
$filename = $uploadfile;
//echo "<BR>File name: $filename<Br>";
echo "File Uploaded: $file <br>";
echo '<pre>';
if(move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)){
echo("File exists, and was successfully uploaded.\n");
//echo("<br>Visually inspect data before submitting.\n");
}else{
echo("Possible file upload attack!\n");
}
echo ("Here is some more debugging info:\n");
print_r($_FILES);
print "</pre> ";
$path = $filename;
$row = 0;
$fp = fopen ("$filename","r");
while ($data = fgetcsv ($fp, 1000, ",")) {
$num = count ($data);
$category = $data[3];
$pieces = explode("|", $category);
Now what I need to be able to do is create a temporary table with a category name, parent ID and child ID. then I need to select each offset and import them into the temporary table and set the parent and child id for each category.
Can someone point me in the right direction to do this? Also I was getting some offset errors when I was testing the explode(). I think it is because some of the categories have different depths then the others. I would need to error check this.
Any help would be appreciated