Jump to content

[SOLVED] My Upload script isnt working - need fresh look.


iPixel

Recommended Posts

The script seems to run fine, just the file wont upload and i get the error msg i echo.

 

<?php
if($job == "uploadfile")
{
	echo "Uploading file...";

	// Where the file is going to be placed 
	$target_path = "CompanyPolicies/";

	// Add the original filename to our target path.  
	//Result is "uploads/filename.extension"
	$target_path = $target_path . basename( $_FILES['thefile']['name']); 

	if(move_uploaded_file($_FILES['thefile']['tmp_name'], $target_path)) 
		{
			echo "The file ".  basename( $_FILES['thefile']['name']). " has been uploaded";
		} 
	else
		{
			echo "There was an error uploading the file, please try again!";
		}

}
else
{
?>
        <form enctype="multipart/form-data" action="admin.php" method="post">
            <input type="hidden" name="task" id="task" value="cp_upload" />
            <input type="hidden" name="job" id="job" value="uploadfile" />
            Choose a file to upload: <input type="file" name="thefile" />
            <input type="submit" value="UPLOAD" style="height:20px; color:#993333;" />
        </form> 
<?php
}
?>

Get php to tell you why the move_uploaded_file() is failing by turning on full php error reporting. Add the following two lines immediately after your first opening <?php tag -

 

ini_set ("display_errors", "1");
error_reporting(E_ALL);

Warning: move_uploaded_file(CompanyPolicies/TEST_PDF.pdf) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\Inetpub\wwwroot\Newton\cp_upload.php on line 26

 

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\WINDOWS\Temp\php815.tmp' to 'CompanyPolicies/TEST_PDF.pdf' in C:\Inetpub\wwwroot\Newton\cp_upload.php on line 26

 

 

I assume this means the folder CompanyPolicies does not have permission to have files palced inside it ?

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.