You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Sharmistha Chatterjee <sh...@gmail.com> on 2012/03/22 09:48:20 UTC

[users@httpd] Uploading a file using HTTp to apache web server.

Hi,

I am new to apache web server. My objective is to upload a file from a C
program.

I am facing an issue in uploading a file to APACHE web server on
Linux. I am not able to find the uploaded file at the server.

My post request has the following data and the HTTP response is also
OK. if I dont specift  /x.txt in the uri.


But if I specify /x.txt thenit is  HTTP 404



POST /x.txt  HTTP/1.1 \r\n

User Agent : My server  \r\n

Host: x.x.x.x:80 \r\n

Accept:  */* \r\n

Content-Length:  5 \r\n

Content-Type : text\plain \r\n\r\n



Hello \r\n\r\n



The error log on paache shows.



[error][client x.x.x.x] File does not exist /home/users/priya/
public_html/x.txt



where  /home/users/priya/public_html has been set to
document_directory in httpd.conf



Please help me , I am not able to fix this issue.




Regards,
Sharmistha

Re: [users@httpd] Uploading a file using HTTp to apache web server.

Posted by Sharmistha Chatterjee <sh...@gmail.com>.
After making suffiecient study I had posted the question as I didnt find
anyway where there are reading a plain/text/jpeg/video data . Php is
reading form data everywhere from url encoded forms.
Anyways sorry for incovenience is its off the topic.

Regards,
Sharmistha

On Thu, Mar 22, 2012 at 4:21 PM, Tom Evans <te...@googlemail.com> wrote:

> On Thu, Mar 22, 2012 at 10:39 AM, Sharmistha Chatterjee
> <sh...@gmail.com> wrote:
> >
> > Hi,
> >
> > I am trying to upload a file to apache web server . The post request is
> successful. I am getting HTTP OK
> >
> > Post request
> >
> > POST /upload.php?save-as=t.txt HTTP/1.1
> > Host: x.x.x.x
> >
> > Content-Length: 5
> > Content-Type: text/plain
> >
> > Hello
> > ---------------------------------------------------------------------
> > Now with the .php script upload.php I am trying to save the file as
> t.txt .. Can anyone point me where I am going wrong the file is not getting
> saved in the sever.
> >
> > <?php
> > $filename= "t.txt";
> > $content = $_POST["body"]; ///?? I think there is something wrong here
> > $fp = fopen($filename,"a"); // $fp is now the file pointer to file
> $filename
> > if($fp){
> > fwrite($fp,$content); // Write information to the file
> > fclose($fp); // Close the file
> > echo $filename . " has been saved sucessfully.";
> > }
> > else {
> > echo $filename . " was not saved successfully.";
> > }
> > ?>
> >
> >
> > Regards,
> > Sharmistha
> >
>
> Sharmistha
>
> This is not particularly on-topic for the Apache mailing list. Try a
> PHP list, or some books on how browsers communicate with websites.
>
> In order to use things like $_POST in PHP, PHP must receive the post
> data in a format that it can understand, which is either
> 'application/x-www-form-urlencoded' or 'multipart/form-data'. Your
> data is not encoded into any format it can understand - it is just
> 'text/plain'.
>
> You should do some reading/research on how HTTP works, rather than
> bombarding this list with off topic questions. If you still have
> questions after that, come back and ask them.
>
> Cheers
>
> Tom
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
> For additional commands, e-mail: users-help@httpd.apache.org
>
>


-- 
sharmistha

Re: [users@httpd] Uploading a file using HTTp to apache web server.

Posted by Tom Evans <te...@googlemail.com>.
On Thu, Mar 22, 2012 at 10:39 AM, Sharmistha Chatterjee
<sh...@gmail.com> wrote:
>
> Hi,
>
> I am trying to upload a file to apache web server . The post request is successful. I am getting HTTP OK
>
> Post request
>
> POST /upload.php?save-as=t.txt HTTP/1.1
> Host: x.x.x.x
>
> Content-Length: 5
> Content-Type: text/plain
>
> Hello
> ---------------------------------------------------------------------
> Now with the .php script upload.php I am trying to save the file as t.txt .. Can anyone point me where I am going wrong the file is not getting saved in the sever.
>
> <?php
> $filename= "t.txt";
> $content = $_POST["body"]; ///?? I think there is something wrong here
> $fp = fopen($filename,"a"); // $fp is now the file pointer to file $filename
> if($fp){
> fwrite($fp,$content); // Write information to the file
> fclose($fp); // Close the file
> echo $filename . " has been saved sucessfully.";
> }
> else {
> echo $filename . " was not saved successfully.";
> }
> ?>
>
>
> Regards,
> Sharmistha
>

Sharmistha

This is not particularly on-topic for the Apache mailing list. Try a
PHP list, or some books on how browsers communicate with websites.

In order to use things like $_POST in PHP, PHP must receive the post
data in a format that it can understand, which is either
'application/x-www-form-urlencoded' or 'multipart/form-data'. Your
data is not encoded into any format it can understand - it is just
'text/plain'.

You should do some reading/research on how HTTP works, rather than
bombarding this list with off topic questions. If you still have
questions after that, come back and ask them.

Cheers

Tom

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] Uploading a file using HTTp to apache web server.

Posted by Sharmistha Chatterjee <sh...@gmail.com>.
  Hi,

I am trying to upload a file to apache web server . The post request is
successful. I am getting HTTP OK

Post request

POST /upload.php?save-as=t.txt HTTP/1.1
Host: x.x.x.x
Content-Length: 5
Content-Type: text/plain

Hello
---------------------------------------------------------------------
Now with the .php script upload.php I am trying to save the file as t.txt
.. Can anyone point me where I am going wrong the file is not getting saved
in the sever.

<?php
$filename= "t.txt";
$content = $_POST["body"]; ///?? I think there is something wrong here
$fp = fopen($filename,"a"); // $fp is now the file pointer to file
$filename
if($fp){
fwrite($fp,$content); // Write information to the file
fclose($fp); // Close the file
echo $filename . " has been saved sucessfully.";
}
else {
echo $filename . " was not saved successfully.";
}
?>


Regards,
Sharmistha
 [image: Sharmi1282 is online now]

On Thu, Mar 22, 2012 at 2:51 PM, Sharmistha Chatterjee <
sharmi.chatterjee@gmail.com> wrote:

> Thank you. How the script will read the results, should it read using HTTP
> GET (as I am new to this).  Is there any information available regarding
> this anywhere in the website.
>
> Regards,
> Sharmistha
>
> On Thu, Mar 22, 2012 at 2:24 PM, Daniel Gruno <ru...@cord.dk> wrote:
>
>> On 22-03-2012 09:48, Sharmistha Chatterjee wrote:
>>
>>> Hi,
>>> I am new to apache web server. My objective is to upload a file from a C
>>> program.
>>> I am facing an issue in uploading a file to APACHE web server on
>>> Linux. I am not able to find the uploaded file at the server.
>>> My post request has the following data and the HTTP response is also
>>> OK. if I dont specift  /x.txt in the uri.
>>> But if I specify /x.txt thenit is  HTTP 404
>>>
>>> POST /x.txt  HTTP/1.1 \r\n
>>>
>>> User Agent : My server  \r\n
>>>
>>> Host: x.x.x.x:80 \r\n
>>>
>>> Accept:  */* \r\n
>>>
>>> Content-Length:  5 \r\n
>>>
>>> Content-Type : text\plain \r\n\r\n
>>>
>>> Hello \r\n\r\n
>>>
>>> The error log on paache shows.
>>>
>>> [error][client x.x.x.x] File does not exist /home/users/priya/
>>> public_html/x.txt
>>>
>>> where  /home/users/priya/public_html has been set to
>>> document_directory in httpd.conf
>>>
>>> Please help me , I am not able to fix this issue.
>>>
>>> Regards,
>>> Sharmistha
>>>
>> The POST request type is not an upload method per se, but rather one of
>> several methods of delivering data in a request. If you wish to upload a
>> file, you should either use POST to send data to a script on your server,
>> which reads the data and saves it, or use the PUT method with a DAV service.
>>
>> For example: You have upload.php on your server which reads the POST
>> contents and saves it as a file;
>>
>> POST /upload.php?save-as=t.txt HTTP/1.1
>> Host: somehost
>> Content-Length: 5
>> Content-Type: text/plain
>>
>> Hello
>>
>>
>> The script will then read your contents and save it using some
>> php/whatever-language method you define.
>>
>> With regards,
>> Daniel.
>>
>> ------------------------------**------------------------------**---------
>> To unsubscribe, e-mail: users-unsubscribe@httpd.**apache.org<us...@httpd.apache.org>
>> For additional commands, e-mail: users-help@httpd.apache.org
>>
>>
>
>
> --
> sharmistha
>



-- 
sharmistha

Re: [users@httpd] Uploading a file using HTTp to apache web server.

Posted by Sharmistha Chatterjee <sh...@gmail.com>.
Thank you. How the script will read the results, should it read using HTTP
GET (as I am new to this).  Is there any information available regarding
this anywhere in the website.

Regards,
Sharmistha

On Thu, Mar 22, 2012 at 2:24 PM, Daniel Gruno <ru...@cord.dk> wrote:

> On 22-03-2012 09:48, Sharmistha Chatterjee wrote:
>
>> Hi,
>> I am new to apache web server. My objective is to upload a file from a C
>> program.
>> I am facing an issue in uploading a file to APACHE web server on
>> Linux. I am not able to find the uploaded file at the server.
>> My post request has the following data and the HTTP response is also
>> OK. if I dont specift  /x.txt in the uri.
>> But if I specify /x.txt thenit is  HTTP 404
>>
>> POST /x.txt  HTTP/1.1 \r\n
>>
>> User Agent : My server  \r\n
>>
>> Host: x.x.x.x:80 \r\n
>>
>> Accept:  */* \r\n
>>
>> Content-Length:  5 \r\n
>>
>> Content-Type : text\plain \r\n\r\n
>>
>> Hello \r\n\r\n
>>
>> The error log on paache shows.
>>
>> [error][client x.x.x.x] File does not exist /home/users/priya/
>> public_html/x.txt
>>
>> where  /home/users/priya/public_html has been set to
>> document_directory in httpd.conf
>>
>> Please help me , I am not able to fix this issue.
>>
>> Regards,
>> Sharmistha
>>
> The POST request type is not an upload method per se, but rather one of
> several methods of delivering data in a request. If you wish to upload a
> file, you should either use POST to send data to a script on your server,
> which reads the data and saves it, or use the PUT method with a DAV service.
>
> For example: You have upload.php on your server which reads the POST
> contents and saves it as a file;
>
> POST /upload.php?save-as=t.txt HTTP/1.1
> Host: somehost
> Content-Length: 5
> Content-Type: text/plain
>
> Hello
>
>
> The script will then read your contents and save it using some
> php/whatever-language method you define.
>
> With regards,
> Daniel.
>
> ------------------------------**------------------------------**---------
> To unsubscribe, e-mail: users-unsubscribe@httpd.**apache.org<us...@httpd.apache.org>
> For additional commands, e-mail: users-help@httpd.apache.org
>
>


-- 
sharmistha

Re: [users@httpd] Uploading a file using HTTp to apache web server.

Posted by Daniel Gruno <ru...@cord.dk>.
On 22-03-2012 09:48, Sharmistha Chatterjee wrote:
> Hi,
> I am new to apache web server. My objective is to upload a file from a 
> C program.
> I am facing an issue in uploading a file to APACHE web server on
> Linux. I am not able to find the uploaded file at the server.
> My post request has the following data and the HTTP response is also
> OK. if I dont specift  /x.txt in the uri.
> But if I specify /x.txt thenit is  HTTP 404
>
> POST /x.txt  HTTP/1.1 \r\n
>
> User Agent : My server  \r\n
>
> Host: x.x.x.x:80 \r\n
>
> Accept:  */* \r\n
>
> Content-Length:  5 \r\n
>
> Content-Type : text\plain \r\n\r\n
>
> Hello \r\n\r\n
>
> The error log on paache shows.
>
> [error][client x.x.x.x] File does not exist /home/users/priya/
> public_html/x.txt
>
> where  /home/users/priya/public_html has been set to
> document_directory in httpd.conf
>
> Please help me , I am not able to fix this issue.
>
> Regards,
> Sharmistha
The POST request type is not an upload method per se, but rather one of 
several methods of delivering data in a request. If you wish to upload a 
file, you should either use POST to send data to a script on your 
server, which reads the data and saves it, or use the PUT method with a 
DAV service.

For example: You have upload.php on your server which reads the POST 
contents and saves it as a file;

POST /upload.php?save-as=t.txt HTTP/1.1
Host: somehost
Content-Length: 5
Content-Type: text/plain

Hello


The script will then read your contents and save it using some 
php/whatever-language method you define.

With regards,
Daniel.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org