So I have this code which is part of a CSV Importer:
Code:
public function saveImageWithUrl($image)
{
$attach_id = false;
$upload_dir = wp_upload_dir();
//get data
$image_data = @file_get_contents($image);
//get the filename
$filename = basename($image);
//create the dir or take the current one
if (wp_mkdir_p($upload_dir['path'])) {
$file = $upload_dir['path'] . '/' . $filename;
} else {
$file = $upload_dir['basedir'] . '/' . $filename;
}
Right now, when the importer imports a image, it names the image based on it`s URL (E.g imageshack.us/a/img585/4739/8jp6.png, would mean it would name it 8jp6.png).
However, I want the importer to name it based on it`s WP Post Title. I tried to manipulate the code but failed, if anyone can help, it`d be much appreciated, thanks!