Page 1 of 1

file upload

Posted: Sat Jun 19, 2010 2:12 pm
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";

}



?>

Re: file upload

Posted: Sat Jun 19, 2010 2:18 pm
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";
}

?>

Re: file upload

Posted: Sat Jun 19, 2010 3:00 pm
by digrev
Thanks a lot my friend

Re: file upload

Posted: Sun Jun 20, 2010 2:42 pm
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