Documente Academic
Documente Profesional
Documente Cultură
</form>
</form>
Whats Happenin?
When the "Upload File" button is clicked, the
file specified in the <input type="file"
name="UploadFile"/> is automatically posted
to a temporary folder on the webserver
When the "Upload File" button is clicked, the
file specified in the <input type="file"
name="UploadFile"/> is automatically posted
to a temporary folder on the webserver..
What’s goin on – move_uploaded_file()?
The first parameter of the function -
$_FILES['uploadFile'] ['tmp_name'], becomes a
reference to the file as the function prepares
to move it to its final destination.
The second parameter -
“/uploads/FILES['uploadFile'] ['name']}", is a
relative path to the folder were the file will be
permanently saved.
The last part of the path includes the code -
{$_FILES['uploadFile'] ['name']}. This can be
interpreted as the name of the file which was
entered into the file text box named
"uploadFile".
move_uploaded_file cont.
In short, the move_uploaded_file() function
moves the file from a temporary upload folder
to the folder ($_FILES['uploadFile']
['tmp_name']) to the folder (“/uploads”) and
the file is saved with the same name as
entered by the user ({$_FILES['uploadFile']
['name']}).
Files can be uploaded to any directory on the
web server, however, the destination folder
must have "write" access permissions.
Setting Permissions
On our local machines,
set up permissions by
right clicking on the
folder and choosing
properties.
Then click the ‘Allow’
button to allow full
control of the folder.
On a web server, set
the permissions to 777.
Uh-Oh!
We have not considered what happens when
a user attempts to upload a file that exceeds
size limits, if the upload folder does not have
appropriate security permissions, or some
unforeseen network issue prevents the entire
file from being uploaded.
To improve the file upload code, we must
provide routines that check for errors and
provide feedback to the user on how to
correct these problems.
Adding Error Checking
if ($_POST['Submit'] == "Upload File"){
move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'],
"uploads/{$_FILES['uploadFile'] ['name']}");
</form>
Otherwise (a ($_FILES['uploadFile']
move_uploaded_file document) we "../uploads/".$filenameSafe);
['tmp_name'], send a blank
dbInsert($filenameSafe,'',$fileType);
value:
Wrapping up
It may take some fine tuning – but this will
leave you with a working script to upload
images and documents.
Note: GD does NOT work with .gif files
because the technology that makes .gif files is
copyrighted.
Another great piece of software to manipulate
images is ImageMagick.