Upload a File to MySQL Database using PHP
HTML-код
- Опубликовано: 9 фев 2025
- Learn how to upload a file or an image to the database using php and also to store that file at a particular location for future use.
SOURCE CODE : www.dropbox.co...
Link to My previous videos:
Login page using php : • Login Form In PHP And ...
Enter data into database using form : • Insert data into MySQL...
Thanks For Watching!
Track: Kozah - Haha [NCS Release]
Music provided by NoCopyrightSounds.
Watch:
Free Download / Stream: ncs.io/HahaYO
thankyou so much tried so many things but this worked on one go
❤️❤️
Can u please show me the structure from your table in phpmyadmin? Thank you very much!
it´s great, just what i need :D keep it up!
Thanks! Will keep doing more :)
Thanks pooo. God bless!
did you have to go into the terminal to give daemon access to the directory in which the file was to be added for it to successfully upload?
Yes server needs to have access to the file directory. If running on local you don’t need to
Do more
Do share it! It will help me make more :)
I am getting this error
Warning: move_uploaded_file(): Unable to move 'C:\xampp\tmp\php3684.tmp' to 'images/6602-pastry.jpg'
Could you please help?
Is the uploaded file path correct?
check if the folder images/ exists on your server, move_uplodaded_file() can't create directories
❤️❤️
Thank you it worked for me. great video
Thank you so much!❤️
Anyone help, my file is not store in folder or not inserted data in database,path is correct,I use enctype,also but didn't get
works perfectly!! thank you so much!!!
❤️
I am getting error Undefined array key "files" in $tname = $_FILES["files"]["tmp_name"];
Check folder if created
The upload dir is directed to the folder named 'images' right? And you create that folder in the folder project right?
Yes sir, but you can create the folder anywhere and just give the path to it
@@CodeFlix12 okay. Thank you for being attentive to the comments 😊
❤️❤️
@@CodeFlix12 sir i have problem on this "undefined index and its the variable $tname_$FILES["files"]["tmp_name"];" but aside that the file is uploaded to the data base but not in the folder
Check if location given is correct
hye, after we success this, hot to view that file? i hope you reply
Hye, can i know what type did you used for image in database table? varchar or blob?
Varchar
@@CodeFlix12 thank you
Thanks for the tutorial 🙌
Thank you!
Hi there, having trouble: what filetype do we set in mysql for id, title, and image? Also file not uploading to server....
ID is int, title is varchar, image is text or varchar whatever you want
@@CodeFlix12 Ok thanks - and any idea why the file itself might not be uploading? I've specified a folder in my remote server, but nothing's being uploaded
You don't upload file to db, you upload file path. You upload file to a folder. So there is an issue with moving the uploaded file to the folder, check the folder, its path and the move_uploaded_file function
Thanks alot dude
♥️♥️♥️
Is it possible to write PHP which will search the database using file name then download the file which this above code uploads to the server >> If yes plz help me
Try mixing my code from some videos
Ooof, I need some help,
First I'm trying to upload audio and not an image, would you know what type of value that'd be in phpMyAdmin
Second, some of my names are different so here's my code: docs.google.com/document/d/1NjsQSV4MBjCpikb49PrhO5H7VGCNf9EqdXdTIaAzkpw/edit?usp=sharing
I have one thing saying "Notice: Undefined index: files in /storage/ssd3/118/16092118/public_html/podcastSaver.php on line 26
"
and also it's echoing me back "Error" instead of "File Successfully uploaded", please help!
Can u tell what settings u did for database
Nothing, just created a default one
Hi, may i know how is the 'files' come from at line 39?? I keep getting undefined index :files?
Files is for the files that you upload and it is the type fiir it. Undefined when there is no file passing or error in path
For me too, i cant find the 'files' reference name on the HTML page, just keeps getting undefined
@@samueljunior5677 should be file not files
@@youngochiel3798 Thanks mate, after bouncing my head around i figured it out hahahah, it's amazing how an simple letter S can be such a stuborn on the code.
Thaks so much for this
Ive checked and i am connected to my sql database. My image does get uploaded to my folder in my server but my sql ‘INSERT’ command is where i think its going wrong. Do you know what it might be? Which datatype should i use in my sql database?
edit: i got it working. My database had columns that (werent automated} which i did not add information to, i guess that caused the error cause as soon as i deleted them it worked
. Thanks a lot!
No issues, i have shown in video what datatypes to keep! Thanks
@@CodeFlix12 yeah. what datatype did you use to id,title and image. it's not in the video sir
it doesn upload file into database, file needed to be converted into bytes array.
awesome, thank u
♥️♥️
Can you show how to set up the sql table? Thanks you!!
I have shown it sir
@@CodeFlix12 where?
In my vids
You are not REALLY uploading the file to mysql database. You are just uploading it to a folder on web server. Please check your title of the video.
Uploading file is an expensive operation. Best practice is what is shown in the video.
im having error with the move uploaded file and with the tname=$_FILES["file" ] - and on this one, in your vid you put files* inside the square bracket but whenever i try the same it gives me an error, i checked the directory twice and the name spelling but there was nothing wrong
Error is in line above move uploaded
@@CodeFlix12 i did a complete carbon copy of the codes on the vid to try if its working and ofcoure i checked the name of the target directory folder but it still gives the same error
Can you copy paste your code in mail
does it work if i upload just the file path, in your case is "localhost/images/".$pname.
Then when i read data from the databse
can i just use """ file_name """ ???
by the way nice tutorial, very clear and simple.
Yes you can use that
@@CodeFlix12 I tried and it worked thanks you
❤️
nice tutorial but you can try this too ruclips.net/video/Hf8bJiRBPio/видео.html
How do i do the database im new and have no idea what im doing
Just go to ui and on left you will get an option to create new db
Is also applicable for docx files?
Yes for them too
Thank you for the tutorial
❤️
thank you for the tutorial !
Thanks for the comment!
$_FILES["file"]. the "file" goes to what? is it default or i can change into other? cause im getting error Undefined index: file on line 36 and 39
It is the name of the file
Change it in html input type as file in name
@@CodeFlix12 so actually I have 5 input type file and 5 input submit with differents name for each other. but I already wrote the same name there. the errors still shows undefined index
When you give the input type="file" and the name which you give, the ["file"] is the name in that input type
@@CodeFlix12 I have done with it btw, but thanks a lot! 🖤
You are welcome
Thanks so much. This video was very helpful. My only issue is where i should create the images folder.
In the root
@@CodeFlix12 how can we create a directory in root?
Just create where index file is
Can you please tell us how to fetch this pfd file from database and display on our webpage. Thank You.
Check download file using php video
Sir, It worked but it just work for once. after I upload a picture, i cant upload again. Can you help me? Thanks
Is there any error?
I am getting the problem of undefined index file. What should I do?
Check the file that you are uploading
It is not getting the file
@@CodeFlix12 I upload the file and image also goes to database but it gives undefined index error in file 36 and 39.
The file where it redirects, the location of that file is wrong or the path is not correct
But here he only put the name of file in the database. Not the BLOB file.
Yes because saving whole file can take too much time and resources. So save only the name or path. Save actual file in a folder at server to save time and resources by 100x.
You do not upload images to the database. That's too big.
I am looking for an excel file input from the user to my website, and wish to parse the file and store the contents in sql tables. Can anyone help me out with this?
Yep I have a video on that sir
CodeFlix
Can i get a link as I didn’t find anything similar, that would be really helpful.
Thank you!
Search for CodeFlix excel
how about the structure of database?
nothing to discuss about structure of database in this video
id, name, path
thanks:)
❤️❤️
Where do the files get saveed?
How can you add some tex to the image and then display it with this text?
Yes
what is the datatype used for storing files in mysql database? like what's the structure of database?
I store path and note file so datatype text
he gave random number to the file and then uploaded the file in /images directory.. he just entered the name in database, and location.. it is not stored in database, it is stored in filesystem.. to store these kind of files in db u need binary datatype.
On point 🙌
very helpful
♥️♥️
There is an error in the code $_FILES['file'] instead of $_FILES['files'];
No brother, it's file only!
How to make 2 file upload in different input but same submit?
Same way as you do for 1
@@CodeFlix12 if i do that, this 2 file will be in the same id or different id?
Different Id
Different name of input
@@CodeFlix12 Thankyou for your answer🙏
♥️♥️
hi sir, how can i adjust my post content length to the higher byte?
Can you explain that somewhat more?
CodeFlix oh i already solve it by editing the upload_max_filesize in php.ini btw thank you so much because you are so great and very responsive
❤️❤️
Hi, I have got the message:
Warning: move_uploaded_file(images/2753-tree.jpg): failed to open stream: Permission denied in /var/www/html/pages/index.php on line 47
Warning: move_uploaded_file(): Unable to move '/tmp/phphNCigb' to 'images/2753-tree.jpg' in /var/www/html/pages/index.php on line 47 Error
What might be the problem? Thank you!
Are you doing this on a server?
@@CodeFlix12 Yea, I think the issue was something about privileges and if it is allowed to get to the relevant folder as I remember
Yes exactly
What is the data type of image in mysql?
Text
thanks
❤️❤️
can someone answer my question, what if i want it to be pdf does the upload_dir = /pdf or /images
Just make a directory called document and upload anything pdf or image
Thanks for this :)
Happy to help!🙌
sir my program $pname = rand(1000, 10000)."-".$_FILES["file"]["NAME"]; and $tname = $_FILES["files"]["tmp_name"]; Undefined index, how to fix thks.
Are you entering correct file name? I mean valid file name?
@@CodeFlix12 I forgot to create a table XD
@@CodeFlix12 thks, I'll try it later
😂😂
please, help me, how to show file, espesially pdf from mysql (php)
Just get the file path from db and invoke it from the server or local machine
how do we echo the image please help
Just call the select query and bring the last uplaoded image there :)
You did not upload a file to Database, you just uploaded a path of the file
Yes that is what you should do ideally and just take the file and put it in the server
Because you can't do that with phpmyadmin. If you're looking to do that, try searching Google Firebase API. Else, you're stuck with only storing the path of the file.
@@haziqfirdaus4956 you can
@@darklup How?
@@haziqfirdaus4956 google about blobs
Please i am gettong this error Notice Undefined variable: FILES ..pleease any help here
What's the version?
need sql code for table creation
It's easy brother try it
I dont understand.It Doesn't working.the echo is not working and what da freak?
What's the error?
everything fine except that noicy music
Can you please help me make a video on multiple files uploaded
I have made a video please check it out on multiple file upload on php
Please show contents of your database!
Like what do you want exactly?
@@CodeFlix12 i want to know how you have created database for storing a file?
I have used varchar because I just store file location
Good job bro. Kindly help me to create a Registration form with File Upload and save it to localhost database.
Ok brother!
Thank you brother 🙂👍
how to fix "error" ??
Which "error"?
@@CodeFlix12 WHEN I UPLOAD A FILE SAYS "Error" AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA
Can you mail me a screenshot of that?
@@CodeFlix12 i have same problem with that error.
Email me
This is a very helpful video.
Can you please also help me do a tutorial "after the users key in their id (eg 001), users can download the files that I uploaded in the database according to the id"
Thank you very much in advnace! :)
Thank you so much
can i see your database ? thanks
Email me
For what?
File zilla??
No
On your application
@@CodeFlix12 But why this way if there is a filezilla application
Filezilla can't be used to upload a file through your application to the server.
Hey mate you still helping?
Yes
hi, thanks for the tutorial ! I have a problem with my connexion in my DB, i have an error and said the db doesn't exist but i created it in phpmyadmin :(
Check for the upper or lower case. Also check by connecting any other db :)
@@CodeFlix12 Thanks for the response :) Merry Christmas ! In my localhost they said my virtual host was disable I will reinstall everything tonight
Do you have a database named codeflix? If not then make one, else replace the db name in code with your db name
how to upload pdf file?
Just like any other file
use file instead of files
Because it is for one fine upload
In $uploads_dir='/' what we have to give ? Can anyone help me out
This is the variable in which we declare the directory path in which we want to store the images or files. So give the path of the directory where you want the uploaded things to get stored!!
Tqq
@@CodeFlix12 but still iam getting error in move_uploaded_file()
Please make sure the path is correct!! Or the move uploaded file function might have been used incorrectly! Check the correct usage and then try
@@CodeFlix12 I got it ... Tqqq
I got an error. "Undefined index file" . Please help me out
The file you are selecting and uploading has an error and program cannot read it. Please upload a proper file
PHP Notice: Undefined index: file thats the error i am getting
The file is not at the location which you have given! Problem in the file
@@CodeFlix12 is it alright if i can send you the code so that you look at it
Yes sure
Weast
❤️
kklik
This video is very helpful 🙂😊
youtube.com/@my_bts004?si=BVsXfFyWBDum8b-H
❤️❤️
Thank you for the tutorial!!!
♥️♥️