shark0der
Forum Replies Created
-
The filename seems to be OK, I don’t know what’s the cause of your problem. Sorry :-/
what’s the original url/filename that you’re trying to upload?
Here’s an example: https://pastebin.com/raw.php?i=gce5UdQJ
Here’s a copy of what I’ve come up to: https://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.
I fixed 3 issues in this plugin, now you can buy me a beer ??
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.