2 questions
1st Question:
When I upload a file from the client side how do I maintain the file extension?
This is the method that I am currently using(I am sure there is a better way)
**************Upload Form*****************
This is the form
$file_id = date("Hisz");
<input type="hidden" name=MAX_FILE_SIZE value=100000000>
<input type="File" name="userfile" size="30" maxlength="255" accept="image/jpeg, image/pjpeg">
<input type="hidden" name="newname" size="30" maxlength="255" value="<?=$file_id?>">
**************Upload Function*****************
This is the function executed after the form is submited
function do_upload($userfile,$newname)
{
$new_file = 'agents/'.$newname.'.jpg';
if (!copy($userfile, $new_file)) echo "failed to copy file $userfile to $new_file\n";
return;
}
So when the function transfers the file from the tmp directory the name is changes to a string like so 11249493809. however I am not sure how to identify what type of image it is so hardcoded .jpg for extension(I want to dynamically save the file as its original type)
How do I mainain the file estension?
2nd question:
How can I dymanically resize the image to a standard dimension?
Example
if the user uploads a .jpg that is 1024X700px
I want to save the file size as 800X600px
I did not find a function i the manual for this
Thanks for your help in advance