PHP - How to Upload a File to Your PHP Web Server - HTML Form and PHP Script Tutorial.avi

preview_player
Показать описание
This video shows you how to use PHP to upload a file to your PHP web server.

I start with the HTML form, that prompts the user to browse for a file to upload. Things to watch for:

Use the enctype="multipart/form-data" attribute in your form declaration. If you forget that, nothing will work.


The method should be POST: method="post"

Note that the $_FILES["file"] variable is an array with such goodies as:
error, name, type, size, and tmp_file to access;
Рекомендации по теме
Комментарии
Автор

PHP SCRIPT:
<?php
$file_result = "";

if ($_FILES["file"]["error"] > 0)
{
$file_result .= "Oh no! :( A error ocurred trying to upload the file! Please try again"
$file_result .= "Error Code: " . $_FILES["file"]["error"]
} else {

$file_result .=
"Upload: " . $_FILES["file"]["name"] . "<br>" .
"Type: " . _FILES["file"]["type"]. "<br>".
"Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br>" .
"Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";

move_uploaded_file($_FILES["file"]["tmp_name"],
"/full/path/on/server/" . $_FILES["file"]["name"]);

$file_result .= "Congrats :)! You file uploaded succeful!";
}
?>

donfaustinocortizone
Автор

Great Video! Thanks for explaining everything so clearly.


aagraphics
Автор

I really loved your tutorial !
THANK YOU SO MUCH ! It helped me a lot !

laracroftandme
Автор

Very helpful. Just a few notes if they help the list.:

Adding an "echo $file_result;" just before closing the php script (i.e., just before the "?>" puts the text in the variable out to the screen so you don't end up with a blank screen. Also, I and using Xampp on Windows so I needed to use a strange form of the path name to move the file to; like "C:/xamp/tmp/name" where this uses the "/" instead of the "\" windows uses.

willauld
Автор

Thanks a lot man, This video helped me a great deal!! Cheers!

cyroncyrus
Автор

awesome explained^^ Thx and keep it real .

endeshaw
Автор

Can someone please help met at 7:10 on line 17? I don't know what I should write instead of the " /full/path/on/server/" .

Non-disjunction
Автор

@ryzanin There are definitely browser limits, but more importantly, there are limits that can be set in your PHP configuration that will stop you from uploading large files. Use the phpinfo() function to find where your php.ini file is, and then check out the following:

file_uploads
upload_max_filesize
max_input_time
memory_limit
max_execution_time
post_max_size

helpvideoguru
Автор

Why, I get Uploaded succesfully but I don't see the actual files in my server... ? any help?

crtwojtyla
Автор

When I press Upload the File it say Do you want to open or save upload_file.php (624 bytes)?

cameronsasser
Автор

Please help!

I did everything what you did, but when I enter the php page I just see the php code....
I did everything right. 1html file and 1php file (called: upload_file.php)

The HTML file is good... but when I click "Upload the File".... it goes wrong.

PLEASE HELP ME !!!

harmenqwe
Автор

If I do want to rename the file to say for example "inventory" how would I go about doing that?

E
Автор

after writing the form. where do i put it?

benslypierre
Автор

Hi there. I am quite new to PHP. My issue is when I click the upload tab it just links me straight to the PHP file and displays the code. What could be causing this?

darraghryan
Автор

Okay, don't I have to enter my information like my server username and password in order for all this to work?

GiddyTechie
Автор

Damn, it sucks that there is no link here to paste the php or html too. When you're learning this stuff it saves a ton of time...

ThePowerHustler
Автор

Does this work with adding comments and other like tasks?

Jairakiss
Автор

Is it possible to upload a file via a string that was given to the script per POST-Method?
So like the post-info "file" is "C:/.../file.txt" and then the file file.txt gets uploaded. So that I don't have to use a file browser but just copy the directory as a string in a form for example?

dXXPacmanXXb
Автор

thx for the guidebro its just what i needed!

but the confirmation message dosn't work for me
after the upload is completed the page just remains blank

xgenk
Автор

how can upload max size video file i tried but i did not please hellp me

anim