FInally somebody explained us how to do this! Thank you very much for this! For those people who's project is not working properly, please make sure you setted the next permission on the "uploads/" folder on linux. (chmod 0777 uploads/) It allowes your site to create files into the folder.
Here's a little thing that tripped me up: when you're testing it out, make sure you are loading your pages from the server, and not from your computer's file directory. If you are opening the files locally, when you click the 'upload' button, it is going to open the php file, and just show you the code you wrote. If you are using Windows, you'll want the url to start with localhost, not C/Program%20Files or something similar.
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?
Awesome. I'm trying to learn about loading images to a MySQL database into as a BLOB and then recalling it to a page from the Database. Do you have a video about that? If so, I have not found it yet.
I have used this video to make an upload project but for mp3's however that seems really unstable, even after I have added quite a few different mp3-types to the array. Any suggestions? For now I work in localhost
Dear Sir, thank you for sharing.May I know where the uploaded files will be saved?If there are many files from the public, the space may be full on our PC.
Oh no no no noo. The tutorial is pretty good, but checking the ext can pretty much f the whole system up. I recommend checking the MIME type instead (and google to find more security uploadings with php as well). If not then anyone can change uploading file types i.e. myPdf.pdf to myPdf.jpg and wolaaa, it gets uploaded. Also I recommend using the uniqid(mt_rand(), true). Otherwise a good and helpful tutorial.
Too many unneeded variables. once you copy $_FILES['file'] to $file Using the $file array is enough you dont need to assign more variables... This would be a good time to make a video about references/pointers
Thanks for the comment, it just made things clearer and if they're required again they would be useful - but you're right, in this example they're not absolutely required.
Hi Sir Alex, could you please do sample tutorial in php, like login authentication if the user fail to login 3 times the users were going to ban.thank you .
This is fairly easy to do, I'm assuming you know how to use the PHP insert and mysql_query feature. How I do this is I make a database table called "login attempts" to store every login attempt. You can do PHP to select data from there and compare them using mysql_num_rows and see if there are 3 for a specific user. Sorry if this was confusing.
I think its not vulnerable for double extension because he is splitting the filename into a array. He is using as split the "." and he will get a array. If u take "name.php.txt" you will get a array with "name|php|txt". He is taking the last element of the array for the extension wich will be correct in this case. I cant think about a case where this wont work.
Just print out the location of the file inside an HTML img tag, you still need to wait for the file to be uploaded in order to do this, or you can also use AJAX for make it look better. You can archieve this in the client using any HTML5 feature too but that could a bit more advanced.
+John Reeves I'm replying to myself here, but the issue ended up being that the maximum upload size was limited to 2MB by my php.ini file. I raised it, and then my mp3s went through to the uploads folder. Make sure you restart apache/your server so that the changes to php.ini take effect.
that might be because you do not have read & write permission for that folder. Assuming you are testing all this out in your local machine using XAMPP or WAMPP, (on windows) you can select the folder you are trying to move the file to, right click it, go to the Security tab and enable permissions for all users. (on Mac) right click on the desired folder, Get info, select everyone at the bottom, double click on "everyone" and select "Read & Write". I reckon on a domain all the privileges are set by default to read and write but I might be wrong. Hope this helped :) cheers
Nice voice and accent! Not a tutorial for beginners. Way too much mumbo jumbo for people who want to learn a basic file upload in php. Overall, bad! The essence of teaching something is starting from the premise that the people who are learning from you have no idea what they're doing. It takes a skilled educator to move slowly through and explain in a deliberate manner as if talking to a child because that's where learners are at, they are at a childlike state. What would have been constructive is to start from basic file upload and then in subsequent tutorials to add things like file ext and size checking.
I think it is the easiest way he can tell us as spectators how a file transfer script is working. Iam a beginner in php too and i could understand it easily.
This is the first TH-cam tutorial on file upload I have found which actually makes sense. Thanks
aaaareeey chlaaey niii sady haan tee we zalim ah
so is yours too, your videos helps me a lot on learning php specially the mvc one.
Works great. Thanks Alex and PHP Academy. Seems like almost every video you guys post is easy to follow and actually works.
FInally somebody explained us how to do this! Thank you very much for this!
For those people who's project is not working properly, please make sure you setted the next permission on the "uploads/" folder on linux. (chmod 0777 uploads/) It allowes your site to create files into the folder.
Yow bro thanks alot !!
Thanks a lot! This was really helpful
Here's a little thing that tripped me up: when you're testing it out, make sure you are loading your pages from the server, and not from your computer's file directory. If you are opening the files locally, when you click the 'upload' button, it is going to open the php file, and just show you the code you wrote.
If you are using Windows, you'll want the url to start with localhost, not C/Program%20Files or something similar.
thanks bro...out of all youtube videos for file uploading only this one worked thanks a lot
Bravo.!!..just bravo!!!...simple,short,brief and informative...Thank You Very Very Much!!!
Thanks a lot man!!! No online tutorial was helping me, but you! Thanks a lot!
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?
Best file uploading tutorial so far....thanx
this was a lot easier than i was expecting, thanks!
So u can upload files in ur local website folder...but is there a way u can upload a file into a folder on a online host like *awardspace?
samething
Beautifully presented. Thanks!
Thank you very very much for these tutorials. You've been saving my life for the past couple of days.
Awesome. I'm trying to learn about loading images to a MySQL database into as a BLOB and then recalling it to a page from the Database. Do you have a video about that? If so, I have not found it yet.
Thank you very much, you are a great instructor. Sorry for my English.
BRaulio Herrera your English was perfect
I have used this video to make an upload project but for mp3's however that seems really unstable, even after I have added quite a few different mp3-types to the array. Any suggestions? For now I work in localhost
Thank you so much for this, this makes so much sense, keep making good and understandable videos like this!
Great Tutorial! Thank you. Finally I created my script, connected with a lot of inputs. Works so great together :)
but what if 2 ppl upload a file with the same name EXACTLY at the same time.. wont it break and overwright one of the files.
Dear Sir, thank you for sharing.May I know where the uploaded files will be saved?If there are many files from the public, the space may be full on our PC.
maybe I didn't see this but are the only extensions allowed txt and jpg?
you just earned yourself a new follower. Awesome overall
great video, actually sticks to the point
thanks, good work, form the other side of the planet, i only speak spanish but i can undertand your method, thanks friend.
So clear and easy to understand. Thanks
this is just amazing man. totally works. Thanks THANKs... THANKKSSSSSS
thank you! Very easy to follow and works like a charm!
Thanks for the help, the only video I could find that helped me.
You are great my lord! You are so amazing man.
i can see it in the folder on bracket software but there is nothing on the desktop folder please help
Why is there no filesize when uploading a jpg or png file? The size array always says 0?
+AnotherKentPaul same, and my file wont upload
Just tried it and it's returning the $file_name_new as .txttxt?
EDIT: Never mind realised i was still using print_r($file_ext); underneath the code.
Haha! Same thing happened to me.
Thank you very much for the tutorial, very helpful.
How can I find out path of the selected file?
excellent tutorial, keep the good work!
That Ending Though
does this work locally for example with WAMP, or only when files are uploaded to the server.
works locally
awesome video, very informative .
sir do you have a download video ?
Awesome tutorial! What if i want to upload PDF files? Thanks!
you add 'pdf' to the $allowed array.
Works locally but i needed to upload to my hosting server and it doesnt allow me to please help
Oh no no no noo. The tutorial is pretty good, but checking the ext can pretty much f the whole system up. I recommend checking the MIME type instead (and google to find more security uploadings with php as well). If not then anyone can change uploading file types i.e. myPdf.pdf to myPdf.jpg and wolaaa, it gets uploaded.
Also I recommend using the uniqid(mt_rand(), true). Otherwise a good and helpful tutorial.
How would you do this via OOP?
Beautiful - thanks for the info
Thank you. This video was very useful.
any idea how to send a post request to upload.php and got it to save it ?
Notice: Undefined variable: files in /storage/ssd2/642/2185642/public_html/upload.php on line 4
oh nvm i put files xd
Excellent tutorial
Too many unneeded variables. once you copy $_FILES['file'] to $file Using the $file array is enough you dont need to assign more variables...
This would be a good time to make a video about references/pointers
Thanks for the comment, it just made things clearer and if they're required again they would be useful - but you're right, in this example they're not absolutely required.
Hey alex , i don't think this work on mobiles !
nice and concise
You are awesome
do you have a tutorial for an image only ?
Nookummoogliepums Smoochiedumpling
Thank you so much dude!! You are so fucking smart!
can we upload the file without temporary file
Great Tutorial. Thank you!
But it is showing undefined index : tmp_name
what server do you use?
+Αλέξανδρος Τσιγγίλης In min 3:31 you can read it: MAMP. But later on Alex made a video about Laravel's homestead.
Fantastic, thanks!
Does this work on online servers?
Worked, thanks!
how it will save in the xampp
Hi Sir Alex, could you please do sample tutorial in php, like login authentication if the user fail to login 3 times the users were going to ban.thank you .
This is fairly easy to do, I'm assuming you know how to use the PHP insert and mysql_query feature. How I do this is I make a database table called "login attempts" to store every login attempt. You can do PHP to select data from there and compare them using mysql_num_rows and see if there are 3 for a specific user. Sorry if this was confusing.
Thank you it helped me a lot
very informative, thank you =]
Great :)
Great Demonstration (Y)
I would marry you if I was a woman.
Thank you so fckng much !! you are nuts !
SAME ALEX from 2 years a go :)
Oh really?
move_uploaded_file() expects parameter 1 to be string, array given in C:\xampp\htdocs\arms\upload.php on line 30
i have this error. help please :(
Send me a link to your code.
this doesnt work for me when i add mp3 or mp4. i dont know why :(
+emmanuel eden
have you tried adding these file types here?
$allowed= array('txt', 'jpg', 'pdf', 'doc');
Please hepl me!
I need to write video uploader script. How I can do it?
+Azizjan Ayupov This is what you need for uploading videos. Perhaps, you're talking about streaming them. Look for a tutorial on that, if so.
Jerome Carter thank you, friend! I already had done it)
Thank you, it was interesting.
The last if construct does not work, no error message no output, no upload, nothing!
is this not vulnerable for double extension ? name.php.txt ? or something ?is this safe enough for a website ?
Indeed. This is NOT secure for production/live/testing websites. i repeat. DO NOT USE IT!!!
+Sam Host can you explain me why ? in detailed thanks
+Sam Host why ?
security.stackexchange.com/questions/32852/risks-of-a-php-image-upload-form
I think its not vulnerable for double extension because he is splitting the filename into a array. He is using as split the "." and he will get a array. If u take "name.php.txt" you will get a array with "name|php|txt". He is taking the last element of the array for the extension wich will be correct in this case. I cant think about a case where this wont work.
Thank you!
it will be helpful if you add source code link :)
thanks it worked for me..
If you upload a jpg file, how can you show it like if you upload a facebook photo?
Just print out the location of the file inside an HTML img tag, you still need to wait for the file to be uploaded in order to do this, or you can also use AJAX for make it look better. You can archieve this in the client using any HTML5 feature too but that could a bit more advanced.
i tried it for mp3 nothing happened. please help me out
+Kushal Luitel a bit late of a reply, but did you ever figure out how to upload mp3s?
+John Reeves I'm replying to myself here, but the issue ended up being that the maximum upload size was limited to 2MB by my php.ini file. I raised it, and then my mp3s went through to the uploads folder. Make sure you restart apache/your server so that the changes to php.ini take effect.
+John Reeves thanks I'll try it
Checkout how to upload a specific type of file from my html document
thanq
heeeeeeeeeeY!!!!!!1 where are your - choose file button in source???
...ilusianist
Alternative: $ext = pathinfo($file_name, PATHINFO_EXTENSION);
Thanks :)
thx !
Everything works except moving the file to the server's directory!!!
that might be because you do not have read & write permission for that folder. Assuming you are testing all this out in your local machine using XAMPP or WAMPP, (on windows) you can select the folder you are trying to move the file to, right click it, go to the Security tab and enable permissions for all users. (on Mac) right click on the desired folder, Get info, select everyone at the bottom, double click on "everyone" and select "Read & Write". I reckon on a domain all the privileges are set by default to read and write but I might be wrong. Hope this helped :) cheers
that was the problem. I'm using apache web server via ubuntu. I changed the directory permissions and was able to post.
thank you :v
what the fuck is tmp_name
ah ribet banget, ane jga bisa ayo berteman Fb facebook.com/caberawit78
Nice voice and accent! Not a tutorial for beginners. Way too much mumbo jumbo for people who want to learn a basic file upload in php. Overall, bad! The essence of teaching something is starting from the premise that the people who are learning from you have no idea what they're doing. It takes a skilled educator to move slowly through and explain in a deliberate manner as if talking to a child because that's where learners are at, they are at a childlike state. What would have been constructive is to start from basic file upload and then in subsequent tutorials to add things like file ext and size checking.
I think it is the easiest way he can tell us as spectators how a file transfer script is working. Iam a beginner in php too and i could understand it easily.