Jump to content


PHP Upload Files


8 replies to this topic

#1 MKayHavoc

    Young Padawan

  • Members
  • Pip
  • 25 posts

Posted 17 May 2006 - 05:50 AM

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.

#2 designcode

    Young Padawan

  • Members
  • Pip
  • 25 posts

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".

<?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 joe

    Young Padawan

  • Members
  • Pip
  • 115 posts
  • Location:stuck in the middle of cyber space

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. :D :D

sorry, if i can't help enough :D :D

#4 coolaid

    P2L Jedi Master

  • Members
  • PipPipPipPip
  • 1,435 posts
  • Gender:Male
  • Interests:i wonder..

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 designcode

    Young Padawan

  • Members
  • Pip
  • 25 posts

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 MKayHavoc

    Young Padawan

  • Members
  • Pip
  • 25 posts

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 Wybe

    Jedi In Training

  • Members
  • PipPip
  • 399 posts
  • Gender:Male
  • Location:the Netherlands
  • Interests:Graphic design, digital and traditional, street style, graffiti, guerilla drawing, typography, coding, sex

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....

#8 Matthew.

    Official Spammer .Matt

  • Members
  • PipPipPipPip
  • 2,749 posts
  • Gender:Male
  • Location:England

Posted 18 May 2006 - 11:34 AM

View PostWybe, 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....

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 ;) :D

#9 Wybe

    Jedi In Training

  • Members
  • PipPip
  • 399 posts
  • Gender:Male
  • Location:the Netherlands
  • Interests:Graphic design, digital and traditional, street style, graffiti, guerilla drawing, typography, coding, sex

Posted 18 May 2006 - 01:16 PM

View Post.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