file upload

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
digrev
Forum Newbie
Posts: 11
Joined: Sat Jun 19, 2010 1:51 pm

file upload

Post by digrev »

Hi everyone im trying to fileupload but im getting some errors could you help please

here if($myfile_type == "image/gif" || $myfile_type == "image/png" || $myfile_type == "image/jpeg")

Notice: Undefined variable: myfile_type in C:\wamp\www\send.php on line 5

this is my source

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Doc<input name="" type="file" />ument</title>
</head>

<body>
<form action="send.php" method="post" enctype="multipart/form-data">
<input type="file" name="myfile" /><br />
<input type="submit" value="Send" />


</form>
</body>
</html>



<?php

$path_="images";

if($myfile_type == "image/gif" || $myfile_type == "image/png" || $myfile_type == "image/jpeg")
{

copy($myfile,"$path_/$myfile_name") or die("Error");

echo "File uploaded";

}



?>
Last edited by Benjamin on Sat Jun 19, 2010 2:52 pm, edited 1 time in total.
Reason: Added [syntax=php] tags.
JKM
Forum Contributor
Posts: 221
Joined: Tue Jun 17, 2008 8:12 pm

Re: file upload

Post by JKM »

Code: Select all

<?php

$path_="images";
$myfile_type = $_FILES['myfile']['type'];
$myfile = $_FILES['myfile']['name'];

if($myfile_type == "image/gif" || $myfile_type == "image/png" || $myfile_type == "image/jpeg")
{
	move_uploaded_file($_FILES['myfile']['tmp_name'], $path.$myfile) or die("Error");
	echo "File uploaded";
}

?>
digrev
Forum Newbie
Posts: 11
Joined: Sat Jun 19, 2010 1:51 pm

Re: file upload

Post by digrev »

Thanks a lot my friend
gecata83
Forum Newbie
Posts: 1
Joined: Wed Jun 16, 2010 1:43 am

Re: file upload

Post by gecata83 »

JKM shows you an example by book how to upload files .The only thing it may occur is to jump with an error for the slash missed over here
move_uploaded_file($_FILES['myfile']['tmp_name'], $path.$myfile) exactly in this part $path.$myfile i think one slash like that will resolve all problems $path."/".$myfile
Post Reply