• 0

PHP Upload Script Problem?


Question

I have written a simple file upload script but when I go to upload a file i get the following error:

"Forbidden

You don't have permission to access /fileuploader.php" on this server.

Apache/2.0.54 (Win32) PHP/5.0.5 Server at localhost Port 80"

The upload code looks like this:

<?

if($file_name !="")

{

copy ("$file", "c:\\server\htdocs\$file_name") or die ("Could not copy the file");

}

else { die("No File Specified");}

?>

<html><head><title> Upload Complete</title></head>

<body><h3> File Upload Succeded...</h3>

<ul>

<li>Sent: <?php echo "$file_name"; ?>

<li>Sent: <?php echo "$file_size"; ?> bytes

<li>Sent: <?php echo "$file_type"; ?>

</ul>

<a href="<?php echo "file_name" ?>"> Click here to view file</a>

</body

</html>

And heres the form that calls this script:

<form action=fileuploader.php" method = "post" enctype="multipart/form-data">

<input type="file" name = "file" size "50">

<br/>

<input type="submit" value = "Upload File">

</form>

Can anbody help? Is there a problem in the code or with my Apache setup?

Link to comment
https://www.neowin.net/forum/topic/388371-php-upload-script-problem/
Share on other sites

3 answers to this question

Recommended Posts

  • 0

hey mate this is how I would do it, try it.

<?

if($file_submit)

{

$file_submit=$_POST['file_submit'];

$file_name=$_POST['file_name'];

if (!copy("$file_name", "c:\\server\htdocs\$file_name"))

{

echo "failed to copy ".$file_name."";

}

copy ("$file_name", "c:\\server\htdocs\$file_name") or die ("Could not copy the file");

echo"

<html>

<head>

<title> Upload Complete</title>

</head>

<body>

<h3> File Upload Succeded...</h3>

<ul>

<li>Sent: ".$file_name."</li>

<li>Size: ".filesize($filename)." Bytes</li>

<li>Type: ".filetype($file_name)."</li>

</ul>

</body>

</html>

";

}

else

{

?>

<form action="fileuploader.php" method = "post" enctype="multipart/form-data">

<input type="file" name = "file_name" size "50">

<br/>

<input type="submit" value = "Upload File" name="file_submit">

</form>

<?

}

?>

Edited by sebdude
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.