Hi all,
I'm having trouble finding a tutorial that explains to me, exactly what I need.
Basically a I'm looking for a way to upload a file to a specific folder and also make a database entry in MySQL stating the files locatoin.
I have a form with two fields, one for a name/handle the other for a file to be uploaded. I want it to pass this information to a script that will, 1, check the files size, that's its a jpg and that it has the dimension of 245x330, 2, uploads this file to a folder i.e. images/members/, 3, Then makes a database entry, i.e. Ryan Havoc, /images/members/ryan_havoc.jpg.
I'm new to PHP an I'm having loads of problems doing this simple thing.
Thanks in Advance.
PHP Upload Files
Started by MKayHavoc, May 17 2006 05:50 AM
8 replies to this topic
#1
Posted 17 May 2006 - 05:50 AM
#2
Posted 17 May 2006 - 07:11 AM
May be that can help you. I suppose that name field om your page has name "filename" and other for a file to be uploaded has name "file".
I have not tested it. Tell me if it don't work.
<?php
$path = "images/members/";
if (trim($_FILES['file']['name'][$i])!="")
{
$newfile = $path . $_FILES['file']['name'][$i];
move_uploaded_file($_FILES['file']['tmp_name'][$i], $newfile);
print "File: $newfile Uploaded<br>";
}
$name = $_FILES['file']['name'];
$link = mysql_connect("localhost", "dbuser", "dbpass");
$connect = mysql_select_db("mydb");
$sql = "insert into file (name, path) values ('$name', '$path')";
$result = mysql_query($sql);
?>
I have not tested it. Tell me if it don't work.
#3
Posted 17 May 2006 - 07:59 AM
for check file type = image/jpg, image/jpeg
i suggest, u try to search in this web on tutorial section, coz i learn from that tut's.
sorry, if i can't help enough
i suggest, u try to search in this web on tutorial section, coz i learn from that tut's.
sorry, if i can't help enough
#4
Posted 17 May 2006 - 12:07 PM
$_FILES['file']['name'][$i]
whats the [$i] do???
that code seems like it'll work, but i suggest just placing the filename into the database so you can call that image from different directories.
--- edit ---
i just realized [$i] is for arrays, it's not needed in that code above.
Edited by coolaid, 17 May 2006 - 02:25 PM.
#5
Posted 18 May 2006 - 12:36 AM
Oh sorry, I made one for me which uploads multiple files. sorry remove the [$i] from code.
#6
Posted 18 May 2006 - 09:48 AM
Sorry but this code doesn't make any sense to me. :-( I'm really new to PHP.
#7
Posted 18 May 2006 - 10:32 AM
If you're new to PHP learn the basics first so you can at least start to understand file management and mysql databasing.
geeez....
geeez....
#8
Posted 18 May 2006 - 11:34 AM
Wybe, on May 18 2006, 04:32 PM, said:
If you're new to PHP learn the basics first so you can at least start to understand file management and mysql databasing.
geeez....
geeez....
Could of been said a bit less harshly *hint* but in essence i agree. Try reading some tutorials, if all else fails download a script.
designcode, what happened to error checking?!?! lol
#9
Posted 18 May 2006 - 01:16 PM
.Matt, on May 18 2006, 06:33 PM, said:
Could of been said a bit less harshly *hint* but in essence i agree.
You're right, and I'm sorry for being wrong. However I still agree with myself and like to reformulate lol.
MKayHavoc, Plunging into something deep as a combination of file management and mysql databasing is something you'll not be very likely to learn from, simply because it is too confuzing. Start simple. Figure out how you can upload a file first, and once you got that working, figure out how you can put stuff into mysql. From there, try inserting the file's info into MySQL and uploading the file also. In other words, start simple.
I really hope you know enough of PHP to start at least, like basic rules about functions, conditionals, etc.
And maybe you and Aussiestinger could help eachother out, because you're looking for almost exactly the same thing.
1 user(s) are reading this topic
0 members, 1 guests, 0 anonymous users
