60 likes | 228 Views
File Uploads. The Form tag. Set the method to “post” The form attribute enctype ="multipart/form-data” must be in the opening form tag Before the file field you must have a hidden field with a name of MAX_FILE_SIZE and the max size of the file in bytes
E N D
The Form tag • Set the method to “post” • The form attribute enctype="multipart/form-data” must be in the opening form tag • Before the file field you must have a hidden field with a name of MAX_FILE_SIZE and the max size of the file in bytes • The file field displays differently in different browsers.
Folder Permissions • The folder you are adding images to must be writable by the web server. • The web server runs as the user apache and is a different user then you are. • You must set the permissions to 777 or rwxrwxrwx on the folder you are going to save in. In this case the images folder. • Use FileZilla or Cyberduck to set the permissions and NOT the Mac interface.
Global Variables • The file is accessed through the global variable $_FILES • If the file form element is called userfile then the file is referenced with $_FILES[“userfile”] • It will be a multi-dimensional array with four sub keys of name, temp_name, size and type.
Simple move • You can use the PHP command move_uploaded_file to transfer the temp file to its new location. • If the temp file is not transferred before the end of the script executing the temp file is automatically deleted.
GD • GD is an extension of PHP that allows you to modify images. • It has basic functionality as compared to Imagemagick.