WordPress.org

Support

Support » Plugins and Hacks » CSV Import for WordPress » [Resolved] Plugin fails to download the image if it contains spaces in filename

[Resolved] Plugin fails to download the image if it contains spaces in filename

  • The copy function throws an error if the image URL contains spaces in it. For example: http://www.domain.com/path/to/file name.png

    I fixed this for myself by replacing spaces with ‘%20’ in csv file but this is rather a workaround then a fix.

    UPDATE: the just mentioned fix doesn’t work as it downloads the images but they are not displayed correctly in posts. Proper URL handling needed.

    http://wordpress.org/extend/plugins/wp-ultimate-csv-importer/

Viewing 13 replies - 1 through 13 (of 13 total)
  • Here’s a quick fix:

    $dir = wp_upload_dir();
    $dirname = 'featured_image';
    $full_path = $dir['basedir'].'/'.$dirname;
    $baseurl = $dir['baseurl'].'/'.$dirname;
    $filename = explode('/',$file_url);
    $file_split = count($filename);
    $nofun_allowed = preg_replace('/[^a-z0-9._-]/', '-', $filename[$file_split-1]);
    $filepath = $full_path.'/'.$nofun_allowed;
    $fileurl = $baseurl.'/'.$nofun_allowed;
    if(is_dir($full_path)){
        $smack_fileCopy = copy($file_url,$filepath);
    }

    I use preg_replace because it’s easier then url-encode/decode and the original filename is not really needed.

    I fixed 3 issues in this plugin, now you can buy me a beer 🙂

    I am pulling my hair out with this. 10000 products no images do you have the csv your using. Help would be greatly appreciated and I will buy u a beer

    I tried your code but filename and type in featured_image folder are just dashes ———————————- Not sure about that

    Here’s a copy of what I’ve come up to: http://ge.tt/37jlxed/v/0?c

    Your filenames probably contain [only] non-ascii characters (like Chinese or something) and what I basically do is to replace all non-alphanum with dashes to there are no spaces or other characters that need to be converted to %20 (or the corresponding hex representation).

    An additional improvement that would be also needed is to add a timestamp to the filenames. It’s needed because the plugin doesn’t check the uniqueness of the filename right now and by uploading an image with the same filename it would get overwritten.

    Can you send me a .csv file that you are using so I can see how you constructed it. Thanks in advance

    wp-content/uploads/featured_image/—-.JPG this is what I get when its imported?

    what’s the original url/filename that you’re trying to upload?

    ABUD.JPG

    The filename seems to be OK, I don’t know what’s the cause of your problem. Sorry :-/

    Plugin Author smackcoders

    @smackcoders

    New version is released with improvements and fixes. Please upgrade and leave your feedback. Hope it works well as expected.

Viewing 13 replies - 1 through 13 (of 13 total)
  • The topic ‘[Resolved] Plugin fails to download the image if it contains spaces in filename’ is closed to new replies.
Skip to toolbar