Posting at the PHPList Forum: PHPlist Forum Index -> Docs, Tips and Tricks Quick Hack. Importing without file uploading. ================================================================= mariovaldez Joined: 01 Jul 2004 Posts: 1 ================================================================= Posted: Thu Jul 01, 2004 9:04 am Post subject: Quick Hack. Importing without file uploading. ================================================================= Hi. I was moving an old mailing list from MailMan to PhpList but when trying to import my old user list, I couldn't. After some minutes struggling with the importing procedure (because my hosting company is using PHP in safe-mode), I decided to change the way I load the user list. Why to upload a file when you can just copy-paste the user list in a textarea? (I was importing with the option "import emails with the same values for attributes"). So I edited the script file admin/import1.php to make it display a textarea where I can just paste or write directly the emails to import. For a screenshot check this: http://www.mariovaldez.net/files/phplist_import.png The changes are as follow (I'm using version 2.8.8 of PhpList): Deleted this from line 23 to 38: Code: ----------------------------------------------------------------- if(!$_FILES["import_file"]) { Fatal_Error("File is either too large or does not exist."); return; } if(empty($_FILES["import_file"])) { Fatal_Error("No file was specified. Maybe the file is too big? "); return; } if (filesize($_FILES["import_file"]['tmp_name']) > 1000000) { Fatal_Error("File too big, please split it up into smaller ones"); return; } if( !preg_match("/^[0-9A-Za-z_\.\-\/\s \(\)]+$/", $_FILES["import_file"]["name"]) ) { Fatal_Error("Use of wrong characters: ".$_FILES["import_file"]["name"]); return; } ----------------------------------------------------------------- and added this at that place: Code: ----------------------------------------------------------------- if(!($_POST["import_elist"])) { Fatal_Error("No list was specified."); return; } ----------------------------------------------------------------- Substitute this code (around line 32): Code: ----------------------------------------------------------------- if ($_FILES["import_file"]) { move_uploaded_file($_FILES['import_file']['tmp_name'], $GLOBALS['tmpdir'].'/'. $_FILES['import_file']['name']); if( !($fp = fopen ($GLOBALS['tmpdir'].'/'. $_FILES['import_file']['name'], "r"))) Fatal_Error("The file ".$_FILES['import_file']['tmp_name']." is not readable !"); $email_list = fread($fp, filesize ($_FILES["import_file"]['tmp_name'])); fclose($fp); unlink($_FILES["import_file"]['tmp_name']); } ----------------------------------------------------------------- Using this: Code: ----------------------------------------------------------------- if ($_POST["import_elist"]) { $email_list = $_POST["import_elist"]; } ----------------------------------------------------------------- And change lines 278 and 279: Code: ----------------------------------------------------------------- The file you upload will need to contain the emails you want to add to these lists. Anything after the email will be added as attribute "Info" of the user. You can specify the rest of the attributes of these users below. Warning: the file needs to be plain text. Do not upload binary files like a Word Document. File containing emails: ----------------------------------------------------------------- Using this: Code: ----------------------------------------------------------------- List you load will need to contain the emails you want to add to these lists. Anything after the email will be added as attribute "Info" of the user. You can specify the rest of the attributes of these users below. Warning: the list needs to be plain text. Do not load binary data. List of emails: ----------------------------------------------------------------- This is a quick hack, I don't know if the delimiter thing works (I think it should) and I don't think the Record Delimiter would make any difference here. Also, the encoding type when calling FormStart function no longer needs to be multipart form-data, but hey... this is a quick hack, not a full rewrite. Wink If you want to try it but don't feel confortable editing the PHP code, you can download the import1.php script file from here: http://www.mariovaldez.net/files/import1_2.8.8.php.bz2. Just download it, decompress it, rename the original admin/import1.php file, move the new file to your /admin directory and test it. Regards, Mario A. Valdez-Ramirez ================================================================= eporue Joined: 01 Jul 2004 Posts: 2 ================================================================= Posted: Thu Jul 01, 2004 10:09 am Post subject: Mario, กก alucinate !! ================================================================= It was great. After struggling with the database for about 3 hours, I can see that your solved it in a very elegant way. กก Muchas gracias !! ================================================================= mcpb Joined: 22 Aug 2004 Posts: 43 ================================================================= Posted: Tue Nov 30, 2004 10:18 pm Post subject: ================================================================= Works like a charm! Very easy to add a user or two any time! GREAT WORK! (What are you going to do next?? Wink)