Forums

[Plugin: CSV Importer] Some problems with this great plugin (27 posts)

  1. pavelevap
    Member
    Posted 2 years ago #

    Hi, I tried other plugins for importing csv, but this simple plugin is great. But there are several problems on my webhosting:

    1) Open_basedir restriction with /tmp directory and function tempnam
    $t_fname = tempnam(md5(''), __CLASS__ . '_');
    I have to change it to $t_fname = @tempnam(md5(''), __CLASS__ . '_');and now it works for me.

    2) Plugin uses file_get_contents which is blocked by my webhoster. Is it possible to change it to curl or any other way?
    I uncomment this line $res = fopen($this->_filename, 'r'); and commented this line: // $res = $this->_patch(); and it works now, but I am not sure if there is any hidden problem...

    3) Feature request: Is it possible to create Post Title from for example three columns? For example author in column 1 and title in column 2 and I want to create post title "author: title". It would be great. I know that I can do it directly in the file, but I need to do it everyday which is really boring...

    Thank you very much for this great little plugin.

  2. dvkob
    Member
    Posted 2 years ago #

    1) Could you post the exact open_basedir restriction error that you're getting? But see 2) first.

    2) Yes, there are several problems here. First of all, the change you've made in 1) no longer makes sense - since you're no longer using _patch() that code is never executed. Second, _patch() fixes some CSV files that would otherwise fail to parse correctly. If you don't use any language other than English in your CSV files and the values are always enclosed in quotes correctly than you might be able to get away with not using _patch().

    All file_get_contents() is doing here is reading a local file into a string, so we don't need curl in this case.

    3) The problem here is that I don't know how to specify which columns should be combined without making the plugin's interface overly complex. Do you?

  3. pavelevap
    Member
    Posted 2 years ago #

    Thank you very much for your answers.

    Ad 1,2) Yes, I know that my changes are not a very good idea, but it was the only way to make your plugin work.

    Error:

    Warning: tempnam() [function.tempnam]: open_basedir restriction in effect. File(/tmp) is not within the allowed path(s): (/var/www/web5/domain.com) in /var/www/web5/domain.com/subdomain.domain.com/wp-content/plugins/csv-importer/File_CSV_DataSource/DataSource.php on line 2310
    
    Warning: fgetcsv() expects parameter 1 to be resource, boolean given in /var/www/web5/domain.com/subdomain.domain.com/wp-content/plugins/csv-importer/File_CSV_DataSource/DataSource.php on line 2157
    
    Warning: fclose(): supplied argument is not a valid stream resource in /var/www/web5/domain.com/subdomain.domain.com/wp-content/plugins/csv-importer/File_CSV_DataSource/DataSource.php on line 2168
    
    Warning: unlink() [function.unlink]: No such file or directory in /var/www/web5/domain.com/subdomain.domain.com/wp-content/plugins/csv-importer/File_CSV_DataSource/DataSource.php on line 2339

    My open_basedir in phpinfo is set to /var/www/web5/domain.com

    Ad 3) Maybe it could be for example csv_post_title_1, csv_post_title_2, etc. (+ custom separator).

  4. dvkob
    Member
    Posted 2 years ago #

    1) Could you create the following php file somewhere in your public_html directory, run it and post its output here?

    <?php
         echo 'Temporary directory is: ' . sys_get_temp_dir();
    ?>

    I'm trying to find out whether PHP can report the correct temporary directory for your installation.

    2) The latest version of the plugin doesn't use function file_get_contents(), so you shouldn't get that error anymore. However, we still need to sort 1) out before the plugin will function correctly.

    3) Right now I'm working on a drag-and-drop interface for the plugin which will allow to combine and rearrange columns easily before importing.

  5. pavelevap
    Member
    Posted 2 years ago #

    Thank you very much for your help...

    1) Fatal error: Call to undefined function sys_get_temp_dir() in ... :-( This function is probably not allowed by my webhoster. I could give you link to my phpinfo, but I do not want to post it here publicly...

    2 and 3) Great! It would be very helpfull. I can beta test if you are interested...

  6. dvkob
    Member
    Posted 2 years ago #

    1) Damn. It looks like you're not allowed to create temporary files, period. I'd contact the webhoster and ask what they can do about it, whether sys_get_temp_dir() function is really blocked and what other functions are blocked too.

  7. realistdreamer
    Member
    Posted 2 years ago #

    Wow, is this a likely problem with many webhosts? Are there any you know where this won't be a problem and otherwise have a good service.

  8. pavelevap
    Member
    Posted 2 years ago #

    I asked my webhoster and he told me that this function is not supported before PHP 5.2.1. My PHP Version is 5.2.0-8+etch15. There are no other blocked functions related to tmp directory. So, is there any other way to make your plugin work on my hosting? I used many plugins and there were no similar problems. Thank you very much for your help...

  9. dvkob
    Member
    Posted 2 years ago #

    realistdreamer: I don't think it's a common problem. At least, it's the first time I hear about a webhosting that restricts access to /tmp, which is a standard directory for temporary files.

    pavelevap: Short answer: it seems like I can't do anything about it. Long answer: with such open_basedir restriction in place, the only directory the plugin can possibly write to is /var/www/web5/domain.com. I can't hardcode this directory into the plugin's source and there's no way for the plugin to determine it automatically. What you can do is either persuade your webhosting to add /tmp to open_basedir or change

    $t_fname = tempnam(md5(''), __CLASS__ . '_');

    to

    $t_fname = tempnam('/var/www/web5/domain.com', __CLASS__ . '_');

    on line 2310 in File_CSV_DataSource/DataSource.php. But you would have to remember to change it every time you update the plugin, so it's really preferable to add /tmp to open_basedir.

  10. paintgirl
    Member
    Posted 2 years ago #

    Ok, I hope this is an easy one...

    How do I configure column titles for custom fields and their accompanying values?

    I am using one custom field named "screen" and its value is always a link to an image related to the post.

    Thanks for your help.

  11. dvkob
    Member
    Posted 2 years ago #

    paintgirl: That's probably because you have the same link to an image on each row in the 'screen' column in your file. To be sure I would have to take a look at the file you're trying to import or at least a couple of rows from it.

  12. paintgirl
    Member
    Posted 2 years ago #

    I guess I did a bad job of wording my question before. I'll try again.

    I'm including an image of my "Add New Post" page so I can explain better. I marked the sections A and B so it make more sense. The image is at (www.countymerchant.com/privacy.html)

    I understand if I have a custom field (A) that my column title should be "custom_field_1". And if I have additional custom field that would be "custom_field_2". What I need to know is what is the column title for the value (B).

    Also is there any way to download my posts into a .csv file? Just wondering.

  13. dvkob
    Member
    Posted 2 years ago #

    paintgirl: To have a custom field named "screen" you should have a column named "screen" in your csv file. Values for that field come from the rows in the same "screen" column, not from a different column.

    It's really best explained by example. You should take a careful look at the sample.csv file included with the plugin, import it and examine the resulting posts.

    By default, WordPress can only export posts in its own XML format. There might be plugins that allow you to export posts in a different format though.

  14. paintgirl
    Member
    Posted 2 years ago #

    Thank you, that is exactly what I needed. Worked perfect.

  15. reface
    Member
    Posted 2 years ago #

    I spent the last 7 hours trying to get this plugin to work, but I'm stuck with the following error upon uploading my file:

    "Invalid CSV file: header length and/or row lengths do not match."

    My CSV file however, looks perfect to me. Even the timestamp is OK. The only thing that is different from the sample.csv, is the "new line" which is a small rectangle character in your sample.csv but an actual new line in my CSV. I don't know how to change that though.

  16. reface
    Member
    Posted 2 years ago #

    Managed to get rid of the error by using double-quotes within the posts and saving the file as UTF-8. But when importing that file, the csv_post_title becomes a custom field.

  17. reface
    Member
    Posted 2 years ago #

    Never mind, I'm using Import CSV (http://importcsv.com) now which doesn't choke on my CSV.

  18. dvkob
    Member
    Posted 2 years ago #

    reface: Well, whatever works for you ;)

    Guys, if you expect me to help you with your CSV files, please post them somewhere. I'm not psychic and I can't tell you what's wrong with your file unless I can take a look at it with my own eyes.

  19. markbm
    Member
    Posted 2 years ago #

    Hello Dvkob,

    Thanks for the great plugin. I'm getting the same "Invalid CSV file: header length and/or row lengths do not match." error on import.

    Would you be so kind as to take a look at my csv at:

    online-training-portal.com/sample4.zip

    I really appreciate it...

    Mark

  20. dvkob
    Member
    Posted 2 years ago #

    markbm: Finally got a chance to look at your file. The problem starts at row 17: "How to use Furlnet" and continues on rows below - you don't have two trailing commas that represent empty values for custom_field_1 and custom_field_2. To see what I mean, just look at rows 1 - 16. They all have to be formatted the same way.

  21. dvkob
    Member
    Posted 2 years ago #

    markbm: You can also upgrade to the latest version of the plugin that will handle your file without throwing an error.

  22. YMO
    Member
    Posted 2 years ago #

    I know 3 was an old question, but to combine the titles the best thing to do is use the concatenate function in Excel to do this yourself.

    So far that's worked out pretty well for me (and is how I makeup most of the post body). When you save as a CSV the formula automatically gets kicked out. If you haven't found another way, hope that helps.

  23. dvkob
    Member
    Posted 2 years ago #

    YMO: Great tip! I had a very strong suspicion that concatenating fields is not the job for the plugin. Do you think you could write a short step-by-step instruction on how to combine two fields to form csv_post_title? I would gladly put it in the FAQ.

  24. andreu
    Member
    Posted 2 years ago #

    Some months ago you talked about a problem of tmp dir. I have the same problem and I have a question about it. For the moment, I can do the plugin work making the following change on DataSource.php file:

    $t_fname = tempnam(md5(''), __CLASS__ . '_');

    to

    $t_fname = tempnam('/var/www/web5/domain.com', __CLASS__ . '_');

    But you said that it's really preferable to add /tmp to open_basedir because of the future plugin updates. How can I do that? I can't edit server seetings. Does my webhosting company make this change easily for me?

    Thanks!

  25. uioiu9420
    Member
    Posted 2 years ago #

    Sorry, it's good in English,
    But cannot import Chinese Word.
    Can anyone help me to import Chinese Word?

  26. IrishGuyDublin
    Member
    Posted 1 year ago #

    I came across this thread when I googled the issue of 0 posts being posted so I just thought I'd add a suggested solution here. As per earlier posts my problem was my hosting offering a system tmp dir that wasn't actually writable. So the patch that writes out a new file wasn't working. I figured the one dir we definietly know we have access to at this point is the php upload dir (this is where the csv file is uploaded to and must be writable is we have got this far into the plugin). So we use that instead. To do this, in the file DataSource.php, function _patch(), replace the line

    $t_fname = tempnam(md5(''), __CLASS__ . '_');

    wih

    $t_fname = tempnam(ini_get('upload_tmp_dir'), __CLASS__ . '_');

    This works for me - your mileage may vary. There may well be reasons why we don't want to do this but it seems reasonable to me at this stage.

    Cheers,
    Colm

  27. dvkob
    Member
    Posted 1 year ago #

    IrishGuyDublin: Good thinking. I have a choice between updating the csv parser to the latest version, which doesn't create temporary files and your solution. I'll see what works best.

Topic Closed

This topic has been closed to new replies.

About this Topic