Click to See Complete Forum and Search --> : file upload error on my side
kanuski
12-11-2003, 02:29 AM
I created an html file upload form that does not work from my computer. I spent days trying to find the problem in my code and then found out that other people were using the code with no problems. When I submit a file using IE I get a "The page cannot be found" message and in Netscape I get a "File contains no data" message.
I have shut off my firewall and emptied the cache but it still will not work. I need any ideas you can think of.
I am using WinXP pro and uploading to an Apache server.
Thanks.
Pittimann
12-11-2003, 02:37 AM
Hi!
Can you post some code, please?
Cheers - Pit
kanuski
12-11-2003, 02:43 AM
Sure.
<?PHP
$minUserLevel = 1;
$cfgProgDir = '../phpSecurePages/';
include($cfgProgDir . "secure.php");
include("../connect.php");
include("../functions.php");
?>
<head><title>Add Photos</title>
</head>
<body>
<form enctype="multipart/form-data" action="add2.php" method="POST">
<h3 align="center">Upload a file:</h3>
<br>
<input type="hidden" name="MAX_FILE_SIZE" value="1000">
<input name="userfile" type="file" size="85" onChange="this.form.path.value=this.value;">
<input type=hidden name=path size=95 value="" onChange="this.value=this.form.userfile.value;">
-
<input name="Submit" type=submit value="Upload File">
</form
</body>
</html>
The action page is add2.php
<?
$minUserLevel = 1;
$cfgProgDir = '../phpSecurePages/';
include($cfgProgDir . "secure.php");
include("../connect.php");
include("../functions.php");
$path=$_GET["path"];
$uploadedfile=$_GET["userfile"];
$userfile=$_FILES['userfile']['name'];
$tempfile=$_FILES['userfile']['tmp_name'];
echo "path:$path<br>Uploadedfile: $uploadedfile<br>Userfile: $userfile<br>Tempfile: $tempfile<hr>";
?>
<html>
<head>
<title>Enter Image Information:</title>
</head>
<body bgcolor="#FFFFcc" text="#000000">
<?
// copy uploaded file to directory
if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
echo "yahoo!<br>";
copy($_FILES['userfile']['tmp_name'], "/home/httpd/vhosts/bethelgospelcamp.com/httpdocs/photos/$filename");
} else {
echo "Possible file upload attack. Filename: " . $_FILES['userfile']['name'];
}
chmod ("/home/httpd/vhosts/bethelgospelcamp.com/httpdocs/photos/$filename", 0755); // octal; correct value of mode
?>
</body>
</html>
thanks
Pittimann
12-11-2003, 02:53 AM
Hi!
So far, I only dealt with FTP uploads via PHP. Anyway - one mistake in your code is obvious:
In your add2.php you have:
$path=$_GET["path"];
$uploadedfile=$_GET["userfile"];
But the form's method is set to "Post". That means, you don't have anything in $_GET["path"] and $_GET["userfile"].
Just try to deal with the postvars instead...
Cheers - Pit
kanuski
12-11-2003, 03:27 AM
Thanks Pit,
I was experimenting with the GET method to see if the add2.php page would load and I forgot to set it back again.
The problem I am having is not that the code is not working, but that the code is not being read at all. I can load this page if I type in the address but it will not load using the html form.
If I change the method to GET or the form input type to text the add2.php page loads. Of course there are errors but at least it loads. <input type=file... does not work with my computer. Could it be that my computer and the server have some communication error?
Pittimann
12-11-2003, 03:46 AM
Hi!
I just saw your hidden input:
<input type="hidden" name="MAX_FILE_SIZE" value="1000">
If its' value is evaluated by one of the included files and the size of the file you try to upload is bigger than 1000 Bytes, the upload must fail.
I can't imagine, why the file input shouldn't work on your machine. If you want to try the FTP stuff I'm using - here is the code:
<html>
<head>
<title>Result</title>
</head>
<body>
<?
echo '<font size="2"><div align="center" width="600" style="text-align: left;padding-top: 10"><center><table border ="1" width="600" cellpadding="4" cellspacing="0">';
$ftp_server='YourFTPServer';//put your data here
$conn_id = ftp_connect($ftp_server);
$user="YourFTPUserName";//put your data here
$passwd="YourFTPPassword";//put your data here
$login_result = ftp_login($conn_id, $user, $passwd);
if ((!$conn_id) || (!$login_result)) {
echo '<tr><td><b>****!!!</b></td></tr><tr><td><b>Connection to '.$ftp_server.' (Username: '.$user.') was not successful!<br><br>Just try again later...</b></td></tr>';
die;
}
else {
echo '<tr><td style="padding-top:10;padding-bottom:10">Connection was successful!</td></tr>';
}
ftp_chdir($conn_id, "");
ftp_chdir($conn_id, "DestinationDirectoryOnServer");//put your data here
$destination_file="NameTheFileShallHaveOnServer";//put your data here
echo '<tr><td style="padding-top:10;padding-bottom:10">Filename on server: '.$destination_file.'</td></tr>';
$upload = ftp_put($conn_id, $destination_file, $userfile, FTP_ASCII);
$fileZahl = count(ftp_nlist ($conn_id,""));
if (!$upload) {
echo '<tr><td style="padding-top:10;padding-bottom:10">Upload failed! Most likely you clicked the submit button without having selected a file.<br><br>Go back and <a href="upload.htm" title=" Back to the upload form... ">try again</a>...</td></tr>';
}
else {
echo '<tr><td style="padding-top:10;padding-bottom:10">'.$userfile.' (Name of temporary file on the Server) was uploaded successfully as <font color="green">'.$destination_file.'</font>!</b></font></center></td></tr>';
}
ftp_close($conn_id);
?>
</table>
</font>
</center>
</div>
</body>
</html>
Cheers - Pit