I'm writing an upload file page
Page 1 of 1
I'm writing an upload file page
This is what I have, please keep in mind that I'm a newbie and I'm running WAMP under Windows 2003 Server..<?php
// To check if the submit has been press or been done
if(isset($_GET['submit'])){
$target_path = "upload/";
$target_path .= basename($_FILES['file_to_upload']['name']);
if(move_uploaded_file($_FILES['file_to_upload']['tmp_name'],$target_path)){
echo "The file has been uploaded";
} else {
echo "There was an error";
}
}
?>
<html>
<head>
<title>Upload file</title>
</head>
<body>
<form method="post" action="#" enctype="multipart/form-data"> <! allows you to upload files -->
<input type="text" name="file_name" placeholder="rename file to:"/><br />
<input type="file" name="file_to_upload" /><br />
<input type="submit" name="submit" value="Upload" />
</form>
</body>
</html>
Any input on what I'm missing will be greatly appreciated. Or point me to right direction would be great.
Thanks a lot in advance
Re: I'm writing an upload file page
Although I haven't worked with PHP uploads to much, I think your code would work better like this:<?php
$target_path = "upload/";
if(isset($_GET['submit'])){
move_uploaded_file($_FILES['file_to_upload']['tmp_name'],$target_path))
echo "The file has been uploaded";
} else {
echo "There was an error";
}
?>
<html>
<head>
<title>Upload file</title>
</head>
<body>
<form method="post" action="#" enctype="multipart/form-data"> <! allows you to upload files -->
<input type="text" name="file_name" placeholder="rename file to:"/><br />
<input type="file" name="file_to_upload" /><br />
<input type="submit" name="submit" value="Upload" />
</form>
</body>
</html>
--
~Chris
~Chris
Re: I'm writing an upload file page
coderadm wrote:This is what I have, please keep in mind that I'm a newbie and I'm running WAMP under Windows 2003 Server..
<?php
// To check if the submit has been press or been done
if(isset($_GET['submit'])){
$target_path = "upload/";
$target_path .= basename($_FILES['file_to_upload']['name']);
if(move_uploaded_file($_FILES['file_to_upload']['tmp_name'],$target_path)){
echo "The file has been uploaded";
} else {
echo "There was an error";
}
}
?>
<html>
<head>
<title>Upload file</title>
</head>
<body>
<form method="post" action="#" enctype="multipart/form-data"> <! allows you to upload files -->
<input type="text" name="file_name" placeholder="rename file to:"/><br />
<input type="file" name="file_to_upload" /><br />
<input type="submit" name="submit" value="Upload" />
</form>
</body>
</html>
Any input on what I'm missing will be greatly appreciated. Or point me to right direction would be great.
Thanks a lot in advance
I forgot to mention that when I click on the file to upload... nothing happens. I don't get any errors, all it says is 'no file chosen'.
Does anyone know what could be causing this...?
Re: I'm writing an upload file page
to upload a file try to learn from this code- Code: Select all
<html>
<body>
<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>
</body>
</html>
PHP Script
- Code: Select all
<?php
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
}
?>
Page 1 of 1