$ext = substr("$mainimage", -3, 3);
$path = "../admin/image/";
$filename = time().".".$ext;
$image = $path.$filename;
//$exec = exec("cp $mainimage $image");
When I click onto the image,
this is what appears
Not sure what's going on with that, since I don't know where you are getting the image name. I assume it's grabbing an image from upload?
I use a pretty cool image upload script found at: http://px.sklar.com/code-pretty.html?code_id=111
It uses php to determine image type (no more substr) and saves wherever you want, with whatever name. You may be able to use some of it.
Hope this helps