I'm trying to upload .js files onto my sever. This is the code:

<html>
	<head>
	<title>Add Ubiquity Command</title>
	</head>
	<body>
		<form action="add_ubiquity_cmd.php" method="post" enctype="multipart/form-data">
			Name: <input type="text" name="name" /><br />
			Description: <textarea rows="8" cols="30" name="description"></textarea><br />
			JS File: <input type="file" name="file"><br />
			<input type="submit" value="Add Command" /><br/>
		</form>
		<?php
			if(isset($_POST["name"]))
			{
				$con = mysql_connect("localhost", "usr", "pass");  
				mysql_select_db("alecbenz_general");
				
				if($_FILES["file"]["error"] > 0)
				{
					echo "Error: ".$_FILES["file"]["error"];
				}
				elseif($_FILES["file"]["type"] != "application/x-javascript")
				{
					echo "Error: file not a Javascript file";
				}
				elseif(file_exists("../ubiquity/".$_FILES["file"]["name"]))
				{
					echo "Error: filename already being used.";
				}
				else
				{
					if(!(move_uploaded_file($_FILES["file"]["tmp_name"],"/ubiquity/".$_FILES["file"]["name"])))
					{
						$error = error_get_last();
						echo "Error uploading file:<br />Type:".$error["type"]."<br />Message:".$error["message"];
					}
					else
					{
						echo "File uploaded<br />";
						$sql = "INSERT INTO ubiquity_cmds (name,description,js_filename) VALUES(".$_POST["name"].",".$_POST["description"].",".$_FILES["file"]["name"].")";
						if(mysql_query($sql,$con))
						{
							echo "Command added";
						}
						else
						{
							echo "Error adding command: ".mysql_error();
						}
					}
				}
			}
		?>
	</body>
</html>

I get this error:

Error uploading file:
Type:2
Message:move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpuveovn' to '/ubiquity/cmd_echo.js'

Anyone know what a possible problem might be?

My first guess would be that you don't have write permission on the destination directory.

Try turning on the debug messages by putting this at the top of your page:

error_reporting(E_ALL);
ini_set('display_errors', true);

See if that produces a more helpful error message.

may be permission error of destination directory

I think I found my problem. For some reason, doing /ubiquity/ doesn't work. I'm under the impression that / would be my public_html directory, and so /ubiquity/ would be public_html/ubiquity/. Anyway, I changed it to ../ubiquity/ (the folder I'm in is also located in public_html), and I don't get an error with the file move.

On a Linux server, prefixing any path with / will make it start at the root directory.

So your /ubiquity/ path would look for a folder called ubiquity directly under the root.

This is different for URL's, where / will have the browser start at the web root.
Like, for example, if you had an <a> href /page.php in a page at www.example.com/path/to/page.html , it would send you to www.example.com/page.php .

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.