Jump to content


 


Register a free account to unlock additional features at BleepingComputer.com
Welcome to BleepingComputer, a free community where people like yourself come together to discuss and learn how to use their computers. Using the site is easy and fun. As a guest, you can browse and view the various discussions in the forums, but can not create a new topic or reply to an existing one unless you are logged in. Other benefits of registering an account are subscribing to topics and forums, creating a blog, and having no ads shown anywhere on the site.


Click here to Register a free account now! or read our Welcome Guide to learn how to use this site.

Photo

Upload form not sending files


  • Please log in to reply
27 replies to this topic

#1 samlf3rd

samlf3rd

  • Members
  • 72 posts
  • OFFLINE
  •  
  • Local time:10:21 AM

Posted 22 September 2010 - 10:26 AM

I have a php form that is says it's uploading the files, but I can't find them, here is the code, and yes I am a nube to php-I'm trying:

<?php
/* Handle multiple file upload easily */
/* by Ronny Haryanto <giant@canada.com> */
/* February-ish 1999 */

/* Use it however you want. I'm not responsible for what you do with it. */

/* how many upload slots? */
define("UPLOAD_SLOTS", 7);

/* where to move the uploaded file(s) to? */
define("INCOMING", "http://www.pagepopwebdesign.com/clients/uploads/");

if($REQUEST_METHOD!="POST")
{
/* generate form */
echo "<form enctype=\"multipart/form-data\" method=post>\n";
for($i=1; $i<=UPLOAD_SLOTS; $i++)
{
echo "<input type=file name=infile$i><br>\n";
}
echo "<input type=submit value=upload></form>\n";
}
else
{
/* handle uploads */
$noinput = true;
for($i=1; $noinput && ($i<=UPLOAD_SLOTS); $i++)
{
if(${"infile".$i}!="none") $noinput=false;
}
if($noinput)
{
echo "error uploading. create 150MB coredump instead?";
exit();
}
for($i=1; $i<=UPLOAD_SLOTS; $i++)
{
if(${"infile".$i}!="none" &&
copy(${"infile".$i}, INCOMING.${"infile".$i."_name"}) &&
unlink(${"infile".$i}))
{
echo ${"infile".$i."_name"}." uploaded<br>";
}
}
} /* else */
?>

I changed file permissions to write also for that folder on my server. This is the only file I have for "uploading"-just one php file I named uploads.php-Do I need a processing file of some sort?
Here is the link to the page with the form: HERE

BC AdBot (Login to Remove)

 


#2 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:08:21 AM

Posted 22 September 2010 - 11:05 AM

Your form needs to know where to send the file. One of the parameters of the <form> tag is the 'action' tag. Tray adding an action parameter to your form tag that points to your uploads.php file.

#3 samlf3rd

samlf3rd
  • Topic Starter

  • Members
  • 72 posts
  • OFFLINE
  •  
  • Local time:10:21 AM

Posted 22 September 2010 - 11:46 AM

I thought that was what I did in the beginning,

/* where to move the uploaded file(s) to? */
define("INCOMING", "http://www.pagepopwebdesign.com/clients/uploads/");

Is this wrong? I'm sorry groovicus I'm corn-fused

#4 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:08:21 AM

Posted 22 September 2010 - 12:37 PM

define("INCOMING", "http://www.pagepopwebdesign.com/clients/uploads/");


All that does is tells you PHP that the variable 'INCOMING' is a constant that holds the value "http://www.pagepopwebdesign.com/clients/uploads/". All that does is tells the PHP where to write the files once it gets them. It doesn't tell your form where to send the files. The form that you are creating runs on the client. The PHP code runs on the server. Your form doesn't know anything about PHP. When I click on your link, all I get from the server is the HTML code. You can verify that by right clicking anywhere on your page, and selecting 'view source.' You can see that there is no PHP there; just HTML.

When I submit a file, it has to be sent back to the server where the PHP lives. If you look at the link I gave you, and look at the 'action' attribute, you can see that a form needs to know where data needs to be sent.
<form action="form_action.asp" method="get">
That is telling the form that when the information is submitted, send it back to a file named "form_action.asp" that lives on the server.

Right now, you are missing one simple thing, and I want you to try and figure it out.

#5 samlf3rd

samlf3rd
  • Topic Starter

  • Members
  • 72 posts
  • OFFLINE
  •  
  • Local time:10:21 AM

Posted 22 September 2010 - 02:49 PM

I'm trying, keep getting errors. So I should insert that line of code in my uploads.php file? If so where? And I don't know how to write a .asp file not sure that it matters but my server is linux.

I do understand that the form is simply created by the php code right? (I'm a php nube) So the php code literally "creates" an html form. Neat if I'm right.

If I understand you I need a file in the same directory as my uploads.php file and name it form_action.asp and I also need to insert a line of code into my uploads.php file to tell the server where to place the tangible files?

#6 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:08:21 AM

Posted 22 September 2010 - 03:58 PM

No. You are not understanding at all. What I showed you was an example. If I click on the link that you gave, here is the HTML that is generated:
<form enctype="multipart/form-data" method=post>
<input type=file name=infile1><br>
<input type=file name=infile2><br>
<input type=file name=infile3><br>
<input type=file name=infile4><br>
<input type=file name=infile5><br>
<input type=file name=infile6><br>
<input type=file name=infile7><br>
<input type=submit value=upload></form>

Your PHP creates this code, so yes you got that part right. :thumbsup:

If you look at the first line of your HTML code, it contains a <form> tag. The page that I linked you to shows you what a properly formed form tag looks like.
<form action="form_action.asp" method="get">
You seem to be hung up on the filename; The example could have been like this:
<form action="this_is_my_way_cool_sample_named_file.php" method="get">

Tags have things inside of them called attributes. An attribute gives your browser additional information about that tag. For instance:
<label height="50" width="200">

The label tag in my example here has two attribute tags; one is height and one is width. In your HTML code, your form tag has two attributes also; enctype and method. You are missing a required attribute... the action attribute. You simply need to add the action attribute so that it shows up in your HTML so that the form knows what file to send the data to. In this case, the file that gets the data is the exact same file that created the form.

Also in the future, telling us that 'I keep getting errors' is not helpful. We are not mind readers, nor are we sitting in front of your computer. We have no way of knowing what the errors are.

#7 samlf3rd

samlf3rd
  • Topic Starter

  • Members
  • 72 posts
  • OFFLINE
  •  
  • Local time:10:21 AM

Posted 22 September 2010 - 04:58 PM

Groovicus, I understand more now, I'm just confused as to where to put the line of code in my php file.

I changed this echo "<form enctype=\"multipart/form-data\" method="get">\n";

to this: echo "<form enctype=\"multipart/form-data\" form action="uploads.php" method="get">\n";

And the "errors I am refering to is server errors when I view the web page, I'm getting the following error:

Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/content/p/a/g/pagepop/html/clients/uploads/uploads.php on line 19

I understand that this is because the php code has a flaw.

Bare with me, I'm trying to learn, and your doing a great job of making me learn it step by step, I've been reading stuff trying to figure it out, and I appreciate it.

#8 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:08:21 AM

Posted 22 September 2010 - 05:25 PM

I changed this echo "<form enctype=\"multipart/form-data\" method="get">\n";

to this: echo "<form enctype=\"multipart/form-data\" form action="uploads.php" method="get">\n";


No. You changed the method attribute from 'POST' to 'GET' also. You should not have changed that. Why did you add the word 'form' a second time? Did the example have the word 'form' in there twice?

Edited by groovicus, 22 September 2010 - 05:28 PM.


#9 samlf3rd

samlf3rd
  • Topic Starter

  • Members
  • 72 posts
  • OFFLINE
  •  
  • Local time:10:21 AM

Posted 22 September 2010 - 07:05 PM

Well I changed "get" back to "post" but I am still getting server errors on line 19 (Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /home/content/p/a/g/pagepop/html/clients/uploads/uploads.php on line 19).
After the change my new code looks like this:
<?php

/* how many upload slots? */
define("UPLOAD_SLOTS", 5);

/* where to move the uploaded file(s) to? */
define("INCOMING", "http://www.pagepopwebdesign.com/clients/uploads/");

if($REQUEST_METHOD!="POST")
{
		/* generate form */

		echo "<form enctype=\"multipart/form-data\" action="uploads.php" method="post">\n";
	
		for($i=1; $i<=UPLOAD_SLOTS; $i++)
		{
				echo "<input type=file name=infile$i><br>\n";
		}
		echo "<input type=submit value=upload></form>\n";
}
else
{
		/* handle uploads */
		$noinput = true;
		for($i=1; $noinput && ($i<=UPLOAD_SLOTS); $i++)
		{
				if(${"infile".$i}!="none") $noinput=false;
		}
		if($noinput)
		{
				echo "error uploading. create 150MB coredump instead?";
				exit();
		}
		for($i=1; $i<=UPLOAD_SLOTS; $i++)
		{
				if(${"infile".$i}!="none" &&
				 copy(${"infile".$i}, INCOMING.${"infile".$i."_name"}) &&
				 unlink(${"infile".$i}))
				{
						echo ${"infile".$i."_name"}." uploaded<br>";
				}
		}
} /* else */
?>

Hope

Edited by groovicus, 22 September 2010 - 08:14 PM.


#10 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:08:21 AM

Posted 22 September 2010 - 08:22 PM

Your error is actually in line 13. If you look at the code, notice that when quotation marks come inside a tag, they are preceded by a backslash. If they are not preceded by a backslash, then they are treated as the end of a line of text. Thus the error message.

#11 samlf3rd

samlf3rd
  • Topic Starter

  • Members
  • 72 posts
  • OFFLINE
  •  
  • Local time:10:21 AM

Posted 22 September 2010 - 08:44 PM

Oh boy, really thanks for the help I do appreciate it, please bare with me. I am trying to learn as well, just keep getting confused a little with php, I do understand html.
Are you saying to put a backslash before the quote of my action tag? like: action=\"uploads.php" ?

#12 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:08:21 AM

Posted 22 September 2010 - 08:53 PM

Ok, you need a bit more clarification. The 'action' tag is not a tag. That is an attribute. It is an attribute contained inside of the form tag. But yes, the quotes on attributes need to be preceded by a backslash.

#13 samlf3rd

samlf3rd
  • Topic Starter

  • Members
  • 72 posts
  • OFFLINE
  •  
  • Local time:10:21 AM

Posted 22 September 2010 - 08:56 PM

I changed the code to this with no help: echo "<form enctype=\"multipart/form-data\" action=\"uploads.php" method="post">\n";

#14 samlf3rd

samlf3rd
  • Topic Starter

  • Members
  • 72 posts
  • OFFLINE
  •  
  • Local time:10:21 AM

Posted 22 September 2010 - 08:57 PM

and this too with 2 backslashes in the action attribute: echo "<form enctype=\"multipart/form-data\" action=\"uploads.php\" method="post">\n";

#15 groovicus

groovicus

  • Security Colleague
  • 9,963 posts
  • OFFLINE
  •  
  • Gender:Male
  • Location:Centerville, SD
  • Local time:08:21 AM

Posted 22 September 2010 - 09:13 PM

Do you see where you failed to add back slashes to an attribute?




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users