Discussion:
How to "download" a multi-part file at the "server" side?
Ajay Garg
2013-11-02 12:36:18 UTC
Permalink
Hi all.

I intend to implement a use-case, wherein the client uploads a file in
multi-part format, and the server then stores the file in a mysql database
(after "downloading it at the server side).

I have been unable to find any immediate answers through googling; I will
be grateful if someone could start me in a direction to achieve the
"downloading at server via php" requirement.

(Don't think it should matter, but I use Java to upload a file in
multi-part format).

I will be grateful for some pointers.

Thanks in advance


Thanks and Regards,
Ajay
Ajay Garg
2013-11-02 12:51:45 UTC
Permalink
I just came across http://www.w3schools.com/php/php_file_upload.asp, and
tested it..
It works fine, when the file is uploaded via a form.


It does seem that the client-method might indeed play a role.
Here is my Java code for uploading the file ::


###################################################
HttpClient httpclient = new DefaultHttpClient();

httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION,
HttpVersion.HTTP_1_1);

HttpPost httppost = new HttpPost(URL);
File file = new File("/path/to/png/file.png");

// Send the image-file data as a Multipart-data.
MultipartEntity mpEntity = new MultipartEntity();
ContentBody cbFile = new FileBody(file, "image/png");
mpEntity.addPart("userfile", cbFile);

httppost.setEntity(mpEntity);

HttpResponse response = httpclient.execute(httppost);
###################################################


Any ideas if making a change at the client (Java) OR/AND server (PHP) might
do the trick?
Post by Ajay Garg
Hi all.
I intend to implement a use-case, wherein the client uploads a file in
multi-part format, and the server then stores the file in a mysql database
(after "downloading it at the server side).
I have been unable to find any immediate answers through googling; I will
be grateful if someone could start me in a direction to achieve the
"downloading at server via php" requirement.
(Don't think it should matter, but I use Java to upload a file in
multi-part format).
I will be grateful for some pointers.
Thanks in advance
Thanks and Regards,
Ajay
--
Regards,
Ajay
Shawn McKenzie
2013-11-02 13:29:24 UTC
Permalink
Fairly easy:
http://www.php.net/manual/en/features.file-upload.post-method.php
Post by Ajay Garg
Hi all.
I intend to implement a use-case, wherein the client uploads a file in
multi-part format, and the server then stores the file in a mysql database
(after "downloading it at the server side).
I have been unable to find any immediate answers through googling; I will
be grateful if someone could start me in a direction to achieve the
"downloading at server via php" requirement.
(Don't think it should matter, but I use Java to upload a file in
multi-part format).
I will be grateful for some pointers.
Thanks in advance
Thanks and Regards,
Ajay
Ajay Garg
2013-11-02 13:43:28 UTC
Permalink
Does not work :(


As per the code-snippet I pasted,
$_FILES["userfile"]["name"]

should be
/path/to/png/file.png


However, $_FILES["userfile"]["name"] is empty.
Post by Shawn McKenzie
http://www.php.net/manual/en/features.file-upload.post-method.php
Post by Ajay Garg
Hi all.
I intend to implement a use-case, wherein the client uploads a file in
multi-part format, and the server then stores the file in a mysql database
(after "downloading it at the server side).
I have been unable to find any immediate answers through googling; I will
be grateful if someone could start me in a direction to achieve the
"downloading at server via php" requirement.
(Don't think it should matter, but I use Java to upload a file in
multi-part format).
I will be grateful for some pointers.
Thanks in advance
Thanks and Regards,
Ajay
--
Regards,
Ajay
Ajay Garg
2013-11-02 17:03:06 UTC
Permalink
Hi all.

1.
I could have the proper "$_FILES["userfile"]["name"]" been echoed back, by
replacing
ContentBody cbFile = new
FileBody(file, "image/png");

with
ContentBody cbFile = new
FileBody(file);



2.
However, now I am stuck with the following server-side code.
No matter what I do, I always get a "no" echoed back (specifying that the
file is not copied to its target place).



###########################################################################
<?php

$headers = apache_request_headers();

foreach ($headers as $header => $value)
{
if($header == "active_window_title")
{
$active_window_title = $value;
break;
}
}


$target_path = "/home/ajay/success.png";

move_uploaded_file($_FILES["userfile"]["tmp_name"], $target_path);
if(file_exists($target_path))
{
echo "yes";
}
else
{
echo "no";
}

echo "\n" . $_FILES["userfile"]["name"]; # I always get the proper
file-name echoed.

?>
####################################################################################





Any ideas what stupidity am I making in the PHP code?
Post by Ajay Garg
Does not work :(
As per the code-snippet I pasted,
$_FILES["userfile"]["name"]
should be
/path/to/png/file.png
However, $_FILES["userfile"]["name"] is empty.
Post by Shawn McKenzie
http://www.php.net/manual/en/features.file-upload.post-method.php
Post by Ajay Garg
Hi all.
I intend to implement a use-case, wherein the client uploads a file in
multi-part format, and the server then stores the file in a mysql database
(after "downloading it at the server side).
I have been unable to find any immediate answers through googling; I will
be grateful if someone could start me in a direction to achieve the
"downloading at server via php" requirement.
(Don't think it should matter, but I use Java to upload a file in
multi-part format).
I will be grateful for some pointers.
Thanks in advance
Thanks and Regards,
Ajay
--
Regards,
Ajay
--
Regards,
Ajay
Aziz Saleh
2013-11-02 17:21:09 UTC
Permalink
Post by Ajay Garg
Hi all.
1.
I could have the proper "$_FILES["userfile"]["name"]" been echoed back, by
replacing
ContentBody cbFile = new
FileBody(file, "image/png");
with
ContentBody cbFile = new
FileBody(file);
2.
However, now I am stuck with the following server-side code.
No matter what I do, I always get a "no" echoed back (specifying that the
file is not copied to its target place).
###########################################################################
<?php
$headers = apache_request_headers();
foreach ($headers as $header => $value)
{
if($header == "active_window_title")
{
$active_window_title = $value;
break;
}
}
$target_path = "/home/ajay/success.png";
move_uploaded_file($_FILES["userfile"]["tmp_name"], $target_path);
if(file_exists($target_path))
{
echo "yes";
}
else
{
echo "no";
}
echo "\n" . $_FILES["userfile"]["name"]; # I always get the proper
file-name echoed.
?>
####################################################################################
Any ideas what stupidity am I making in the PHP code?
Post by Ajay Garg
Does not work :(
As per the code-snippet I pasted,
$_FILES["userfile"]["name"]
should be
/path/to/png/file.png
However, $_FILES["userfile"]["name"] is empty.
Post by Shawn McKenzie
http://www.php.net/manual/en/features.file-upload.post-method.php
Post by Ajay Garg
Hi all.
I intend to implement a use-case, wherein the client uploads a file in
multi-part format, and the server then stores the file in a mysql database
(after "downloading it at the server side).
I have been unable to find any immediate answers through googling; I
will
Post by Ajay Garg
Post by Shawn McKenzie
Post by Ajay Garg
be grateful if someone could start me in a direction to achieve the
"downloading at server via php" requirement.
(Don't think it should matter, but I use Java to upload a file in
multi-part format).
I will be grateful for some pointers.
Thanks in advance
Thanks and Regards,
Ajay
--
Regards,
Ajay
--
Regards,
Ajay
Ajay, try changing your mpEntity to:

new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE)

See if it makes a difference.
Ajay Garg
2013-11-02 17:30:39 UTC
Permalink
Hi Aziz.
Thanks for the reply.

Unfortunately, making the change suggested by you does not make any
difference :(


Sorry, Thanks and Regards
Post by Aziz Saleh
Post by Ajay Garg
Hi all.
1.
I could have the proper "$_FILES["userfile"]["name"]" been echoed back, by
replacing
ContentBody cbFile = new
FileBody(file, "image/png");
with
ContentBody cbFile = new
FileBody(file);
2.
However, now I am stuck with the following server-side code.
No matter what I do, I always get a "no" echoed back (specifying that the
file is not copied to its target place).
###########################################################################
<?php
$headers = apache_request_headers();
foreach ($headers as $header => $value)
{
if($header == "active_window_title")
{
$active_window_title = $value;
break;
}
}
$target_path = "/home/ajay/success.png";
move_uploaded_file($_FILES["userfile"]["tmp_name"], $target_path);
if(file_exists($target_path))
{
echo "yes";
}
else
{
echo "no";
}
echo "\n" . $_FILES["userfile"]["name"]; # I always get the proper
file-name echoed.
?>
####################################################################################
Any ideas what stupidity am I making in the PHP code?
Post by Ajay Garg
Does not work :(
As per the code-snippet I pasted,
$_FILES["userfile"]["name"]
should be
/path/to/png/file.png
Post by Ajay Garg
However, $_FILES["userfile"]["name"] is empty.
Post by Shawn McKenzie
http://www.php.net/manual/en/features.file-upload.post-method.php
Post by Ajay Garg
Hi all.
I intend to implement a use-case, wherein the client uploads a file in
multi-part format, and the server then stores the file in a mysql database
(after "downloading it at the server side).
I have been unable to find any immediate answers through googling; I
will
Post by Ajay Garg
Post by Shawn McKenzie
Post by Ajay Garg
be grateful if someone could start me in a direction to achieve the
"downloading at server via php" requirement.
(Don't think it should matter, but I use Java to upload a file in
multi-part format).
I will be grateful for some pointers.
Thanks in advance
Thanks and Regards,
Ajay
--
Regards,
Ajay
--
Regards,
Ajay
new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE)
See if it makes a difference.
Ajay
Bastien
2013-11-02 20:08:03 UTC
Permalink
Thanks,

Bastien
Post by Ajay Garg
Hi Aziz.
Thanks for the reply.
Unfortunately, making the change suggested by you does not make any
difference :(
Sorry, Thanks and Regards
Post by Aziz Saleh
Post by Ajay Garg
Hi all.
1.
I could have the proper "$_FILES["userfile"]["name"]" been echoed back, by
replacing
ContentBody cbFile = new
FileBody(file, "image/png");
with
ContentBody cbFile = new
FileBody(file);
2.
However, now I am stuck with the following server-side code.
No matter what I do, I always get a "no" echoed back (specifying that the
file is not copied to its target place).
###########################################################################
<?php
$headers = apache_request_headers();
foreach ($headers as $header => $value)
{
if($header == "active_window_title")
{
$active_window_title = $value;
break;
}
}
$target_path = "/home/ajay/success.png";
move_uploaded_file($_FILES["userfile"]["tmp_name"],
Try

If(move_uploaded_file($_FILES["userfile"]["tmp_name"], $filename){
Echo "file moves";
}else{
Echo "file doesn't move";
}


Also check the target directory permissions for writing
Post by Ajay Garg
Post by Aziz Saleh
Post by Ajay Garg
$target_path);
if(file_exists($target_path))
{
echo "yes";
}
else
{
echo "no";
}
echo "\n" . $_FILES["userfile"]["name"]; # I always get the proper
file-name echoed.
?>
####################################################################################
Any ideas what stupidity am I making in the PHP code?
Post by Ajay Garg
Does not work :(
As per the code-snippet I pasted,
$_FILES["userfile"]["name"]
should be
/path/to/png/file.png
Post by Ajay Garg
However, $_FILES["userfile"]["name"] is empty.
Post by Shawn McKenzie
http://www.php.net/manual/en/features.file-upload.post-method.php
Post by Ajay Garg
Hi all.
I intend to implement a use-case, wherein the client uploads a file in
multi-part format, and the server then stores the file in a mysql database
(after "downloading it at the server side).
I have been unable to find any immediate answers through googling; I
will
Post by Ajay Garg
Post by Shawn McKenzie
Post by Ajay Garg
be grateful if someone could start me in a direction to achieve the
"downloading at server via php" requirement.
(Don't think it should matter, but I use Java to upload a file in
multi-part format).
I will be grateful for some pointers.
Thanks in advance
Thanks and Regards,
Ajay
--
Regards,
Ajay
--
Regards,
Ajay
new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE)
See if it makes a difference.
Ajay
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Ajay Garg
2013-11-03 06:00:46 UTC
Permalink
Damn... it was a SeLinux firewall :(


I disabled everything on the server, via
sudo setenforce 0
sudo service iptables stop
sudo service ip6tables stop


and the file was then copied onto the server perfectly !!



Sorry for the bother; and thanks a ton to everyone who spared their time in
looking into the (stupid) query of mine.


Sorry again.
Post by Bastien
Thanks,
Bastien
Post by Ajay Garg
Hi Aziz.
Thanks for the reply.
Unfortunately, making the change suggested by you does not make any
difference :(
Sorry, Thanks and Regards
Post by Aziz Saleh
Post by Ajay Garg
Hi all.
1.
I could have the proper "$_FILES["userfile"]["name"]" been echoed
back, by
Post by Ajay Garg
Post by Aziz Saleh
Post by Ajay Garg
replacing
ContentBody cbFile = new
FileBody(file, "image/png");
with
ContentBody cbFile = new
FileBody(file);
2.
However, now I am stuck with the following server-side code.
No matter what I do, I always get a "no" echoed back (specifying that
the
Post by Ajay Garg
Post by Aziz Saleh
Post by Ajay Garg
file is not copied to its target place).
###########################################################################
Post by Ajay Garg
Post by Aziz Saleh
Post by Ajay Garg
<?php
$headers = apache_request_headers();
foreach ($headers as $header => $value)
{
if($header == "active_window_title")
{
$active_window_title = $value;
break;
}
}
$target_path = "/home/ajay/success.png";
move_uploaded_file($_FILES["userfile"]["tmp_name"],
Try
If(move_uploaded_file($_FILES["userfile"]["tmp_name"], $filename){
Echo "file moves";
}else{
Echo "file doesn't move";
}
Also check the target directory permissions for writing
Post by Ajay Garg
Post by Aziz Saleh
Post by Ajay Garg
$target_path);
if(file_exists($target_path))
{
echo "yes";
}
else
{
echo "no";
}
echo "\n" . $_FILES["userfile"]["name"]; # I always get the proper
file-name echoed.
?>
####################################################################################
Post by Ajay Garg
Post by Aziz Saleh
Post by Ajay Garg
Any ideas what stupidity am I making in the PHP code?
Post by Ajay Garg
Does not work :(
As per the code-snippet I pasted,
$_FILES["userfile"]["name"]
Post by Ajay Garg
Post by Aziz Saleh
Post by Ajay Garg
Post by Ajay Garg
should be
/path/to/png/file.png
Post by Ajay Garg
However, $_FILES["userfile"]["name"] is empty.
Post by Shawn McKenzie
http://www.php.net/manual/en/features.file-upload.post-method.php
Post by Ajay Garg
Hi all.
I intend to implement a use-case, wherein the client uploads a file
in
Post by Ajay Garg
Post by Aziz Saleh
Post by Ajay Garg
Post by Ajay Garg
Post by Shawn McKenzie
Post by Ajay Garg
multi-part format, and the server then stores the file in a mysql database
(after "downloading it at the server side).
I have been unable to find any immediate answers through googling; I
will
Post by Ajay Garg
Post by Shawn McKenzie
Post by Ajay Garg
be grateful if someone could start me in a direction to achieve the
"downloading at server via php" requirement.
(Don't think it should matter, but I use Java to upload a file in
multi-part format).
I will be grateful for some pointers.
Thanks in advance
Thanks and Regards,
Ajay
--
Regards,
Ajay
--
Regards,
Ajay
new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE)
See if it makes a difference.
Ajay
Thanks and Regards,
Ajay

Bastien
2013-11-02 13:34:09 UTC
Permalink
Thanks,

Bastien
Post by Ajay Garg
Hi all.
I intend to implement a use-case, wherein the client uploads a file in
multi-part format, and the server then stores the file in a mysql database
(after "downloading it at the server side).
I have been unable to find any immediate answers through googling; I will
be grateful if someone could start me in a direction to achieve the
"downloading at server via php" requirement.
(Don't think it should matter, but I use Java to upload a file in
multi-part format).
I will be grateful for some pointers.
Thanks in advance
Thanks and Regards,
Ajay
Zip the files together and allow the user to download the one zip file
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
Continue reading on narkive:
Loading...