Jump to content

How to upload a file into a server using code in another server using php?


rajeshkr

Recommended Posts

Hi,
I am using a unlimited server for uploading some files but after using so many code , i am not able to achieve my goal.
So now i want i use my current server to php code and upload my files into another server, where limit will not be any issue.
 
Example.
Let's say i have two server ( www.rajesh.com and www.rathor.com),
 
now i am using below code into www.rajesh.com
 
if (file_exists("http://www.rathor.com/demo/rajesh/" . $_FILES["uploadedfile"]["name"]))
	 {
      echo $_FILES["uploadedfile"]["name"] . " already exists. ";
    }
	 else
	  {
      move_uploaded_file($_FILES["uploadedfile"]["tmp_name"],
      "http://www.rathor.com/demo/rajesh/" . $_FILES["uploadedfile"]["name"]);
      echo "Stored in: " . "http://www.rathor.com/demo/rajesh/" . $_FILES["uploadedfile"]["name"];
    }

So i just want to know, is it possible to do?
if yes then how i can achieve this?

Thanks

 

Link to comment
Share on other sites

most of the functions you have in your code won't work using the http:// protocol, and even if they did, what you are doing would be uploading the file to the first server, then moving it to the second server. this would use double your file transfer bandwidth on the first server.

 

so, what exact problem are you trying to solve.

Link to comment
Share on other sites

Doing it your way, anyone could make a script that would transfer his files into your folder on your server. That's why it shouldn't work. You should probably look into FTP section. As an example:



$ftp_server="";
$ftp_user_name="";
$ftp_user_pass="";

$file = "";//tobe uploaded
$remote_file = "";


// set up basic connection
$conn_id = ftp_connect($ftp_server)or die("Unable to connect to server.");


// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);


// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
echo "successfully uploaded $file\n";
exit;
} 
else {
echo "There was a problem while uploading $file\n";
exit;
}

// close the connection
ftp_close($conn_id);
Edited by Cornelius
Link to comment
Share on other sites

most of the functions you have in your code won't work using the http:// protocol, and even if they did, what you are doing would be uploading the file to the first server, then moving it to the second server. this would use double your file transfer bandwidth on the first server.

 

so, what exact problem are you trying to solve.

Hi mac_gyver,

as i mention , i am trying to give user permission to upload files that may be more than 300Mb size but as i increase sizes in php.in, in my php file and in .htaccess file also but it only able to take 20Mb not more than that, so i was thinking if i could transfer to any other server using any mode like you said ftp, 

thank i could able to achieve my goal.

 

Thanks

Link to comment
Share on other sites

as i mention , i am trying to give user permission to upload files that may be more than 300Mb size

 

no, you didn't mention that in this thread. you cannot assume anyone reading your thread knows anything about your previous threads or problems or how this tread relates to any previous thread or problem.

 

have you checked with your web host to find the proper method of changing the upload file size limits on their server? you cannot set them in your .php file because php uses the settings before your php script is even executed. you can only set them in a .htaccess file when php is running as an Apache Server Module (you get a server if you try.) you can set them in a local php.ini when php is running as a cgi/fastcgi application. if your upload script is in a folder, you will likely need to have a php,ini file in the same folder where the script is at. some web hosts use a different name for the php.ini file, such as php5.ini.

 

you must find out if your web host allows you to change the two settings at all (both post_max_size and upload_max_filesize must be change and they must be set to realistic and valid values) and where and how to change them.

Link to comment
Share on other sites

no, you didn't mention that in this thread. you cannot assume anyone reading your thread knows anything about your previous threads or problems or how this tread relates to any previous thread or problem.

 

have you checked with your web host to find the proper method of changing the upload file size limits on their server? you cannot set them in your .php file because php uses the settings before your php script is even executed. you can only set them in a .htaccess file when php is running as an Apache Server Module (you get a server if you try.) you can set them in a local php.ini when php is running as a cgi/fastcgi application. if your upload script is in a folder, you will likely need to have a php,ini file in the same folder where the script is at. some web hosts use a different name for the php.ini file, such as php5.ini.

 

you must find out if your web host allows you to change the two settings at all (both post_max_size and upload_max_filesize must be change and they must be set to realistic and valid values) and where and how to change them.

Hi mac_gyver,

First of all sorry for inconvenience,

My host server is bluehost. i am using php.ini file (5.4 as per control panel of bluehost).

Earlier i was getting error because there was mas 10 MB set for upload limit, then i change into php.ini file to 512 MB for both post_max_size and upload_max_filesize and change the max_execution time limit too.

but now after changing it too, i only able to upload 20 MB not more than that.

I have try everything but it dosen't seem to help me.

i will only left with what you said use php.ini file in same folder.

Let me check with this also and will reply if it worked

 

Thanks

Link to comment
Share on other sites

Between one byte and 2GB is the range of this setting that Apache can work with.

 

The server administrator may set this limit in the web server's configuration file to a value that the web server administrator has chosen to be appropriate - perhaps 20MB.

 

Please consult your hosting provider.

Link to comment
Share on other sites

I'm still not sure what are you trying to do? Do you want users to transfer files from one server to another or what?

 

If not, why are you doing it in PHP? You can do it in CPanel, just make sure (as they said above) with server admins what's the limit.

 

 

20a6z4w.jpg

Link to comment
Share on other sites

I'm still not sure what are you trying to do? Do you want users to transfer files from one server to another or what?

 

If not, why are you doing it in PHP? You can do it in CPanel, just make sure (as they said above) with server admins what's the limit.

 

 

20a6z4w.jpg

Hi,

1- I have a registration page for user.

2- After registration in page , they will login into page.

3- There will be a simple browse (upload button) and php code into server 1 suppose, mysite.com. but this is a shared server so i am not able to upload a file more then 20MB of size and after lot of code changes , i couldn't able to do into this server.

4- So i have an other server 2 myserver.com as dedicated server, where there is no limit to upload.

5- Now i want could i user server 1 to upload into server 2.

 

Hope you understand what i want.

Thanks

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.