$filename=$_FILES["photo"]["tmp_name"];
$extension=end(explode(".", $filename));
$newfilename="1.".$extension;
$target = "image_files/". $newfilename;
if(move_uploaded_file($_FILES['photo']['tmp_name'], $target))
{
echo "Ok";
}
I have create the code above, but how can I upload a re-sized image?
Since PHP is running server-side, PHP won't be able to resize an image before uploading it to the server.
Use imagecopyresized or imagecopyresampled to resize an image with PHP.
It's impossible to resize an image before uploading it to your server, since PHP only works there, what you're trying to do is simply you try to work with an image that doesn't exist in the server-side, so you must upload the image before manipulating it.
if you're worried about the size of the uploaded image and the time it'll consume, then restrict the users to specific image formats and specific size, for example if you're allowing a user to upload his personal message board avatar, only allow really small images or maybe only gif(.gif) images, instead of taking a huge(2MB+) png(.png) image and resizing it to the desired size(say, 52x52).
however I believe it could be achieved by using some client-side code that will take the image you want to upload and resize it on the fly.