Page 1 of 1

*RESOLVED* Upload file to host.

Posted: Sat Sep 20, 2003 6:08 pm
by HungryMind
Hello, I have already searched this forum and looked through many topics on the php.net website, consulted a php friend (but he had to leave early) AND googled my topic and I am still very frustrated. My host is running Red Hat Linux (I don't know if that matters).

I want to be able to upload my php files to the server. That's pretty basic, but I can't get it to work. Here is my html script:

Code: Select all

form.html

<html>
<head><title></title></head>
<body>

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

<input type="hidden" name="MAX_FILE_SIZE" value="1000000">

<B>Select a File to Upload<br></B>

<input type="file" name="$user_file" size="50"><br><br>


<b>Personal Information (NOT OPTIONAL)</b>

<table>
	<tr>
		<td>
		Your full name: 
		</td>
		
		<td>
		<input type="text" name="user_fname" length="20"> &nbsp <input type="text" name="user_lname">
		</td>
	</tr>
	
	<tr>
		<td>
		Your email address:
		</td>
		
		<td>
		<input type="text" name="email_address" size="15"> @ <input type="text" name="username" size="15"> . <input type="text" name="username" size="3">
		</td>
	</tr>
	
	<tr>
		<td valign="top">
		Description of the file: &nbsp &nbsp
		</td>

		<td>
		<textarea name="file_description" cols="34" rows="5" wrap="virtual"></textarea>
		</td>
	</tr>
</table>

<br><input type="submit" value="Upload my file">
</form>

</body>
</html>
=> You can see an example of this page at: http://www.paredes.cc/brandon/form.html

and here is my php code:

Code: Select all

upload.php

<?php
/*	Copyright © 2003 Brandon Paredes. All rights reserved.
	brandon@paredes.cc	*/

if ($user_file == "none"){
	echo "No file specified";
	exit;
}

if (copy($userfile, "/public_html/brandon/uploads/$user_file")) {
	echo "Your file has been sucessfully uploaded.";
} else {
	echo "Your file was not uploaded.";
}		



?>
I am thining that it is a problem with the path, but I have tried many different variants including simply: /uploads/$user_file.

In the SAME directory as these files is a folder called "uploads" as my code shows. So, in conclusion, I do not know why this code is not working. I have beed fiddling with it all day and still, I get nothing. Any help would be greatly appreciated.


Also, i was wondering if it was possible to substitute:

Code: Select all

if ($user_file == "none"){
with

Code: Select all

if (!($user_file)) {
Thank you,
Brandon Paredes

Posted: Sat Sep 20, 2003 6:44 pm
by volka
<input type="file" name="$user_file" size="50">
remove the $, user_file is the value of the name-property not a script variable at this point.

depending on your version of php a read of Before Post Read: Concerning Passing Variables in PHP 4.2+ might be helpful.
Not exactly covering what concerns you it provides an inside of what's happening php4.1 -> php4.2

http://www.php.net/manual/en/features.file-upload.php describes the new way how file uploads are handled.

Posted: Sat Sep 20, 2003 6:51 pm
by HungryMind
Okay, I altered that and now it says:

Warning: copy(/public_html/brandon/uploads//tmp/phphNPCeG): failed to open stream: No such file or directory in /home/paredes/public_html/brandon/upload.php on line 10
Your file was not uploaded.

I think that it is a problem with the path, but I have no idea what it should read!

Posted: Sat Sep 20, 2003 7:14 pm
by HungryMind
Hahahaha, i got it working! It was just as I suspected in my second post. The full path was /home/paredes/public_html/brandon/uploads/

Thank you for your help,
Brandon