Jump to content

remote uploading


gani4u

Recommended Posts

i wrote an remote uploading script

but the script is used to upload the file in the same directory

but i want to modify the script as to upload it to the original path of the file

 

like so

let the file be http//www.xxxxxx.xxx/examples/text.txt

then on normal script its uploaded to

/public_html/text.txt (b'coz i have my remt upl script in /public_html/ directory)

 

but i want it to have the same path of that of the file

i.e.,

/public_html/example/text.txt  (it should of the original file path of the source file)

like

if its

http//www.xxxxxxxxxx.xxx/why/hello.doc

it should be in

/public_html/why/hello.doc

 

the original code is

//the php code//

 

<?php

 

if (isset($_POST['myupload']))

 

{

 

$links_list = $_POST['upload'];

 

$incr = 0;

 

$links = explode("\r\n",$links_list);

 

define('BUFSIZ', 4095);

 

for ( $incr == 0 ; $incr < count($links) ; $incr++ )

 

{

 

$url = $links[$incr];

 

$rfile = fopen($url, 'r');

 

$lfile = fopen(basename($url), 'wb');

 

while(!feof($rfile))

 

fwrite($lfile, fread($rfile, BUFSIZ), BUFSIZ);

 

fclose($rfile);

 

fclose($lfile);

 

}

 

}

 

?>

Link to comment
https://forums.phpfreaks.com/topic/239706-remote-uploading/
Share on other sites

I don't understand why you are handling data the way you are. I'll point out what's wrong with what you're doing, then set you on the right path with a few options.

 

First, if you are uploading data you should verify that the data being posted is actually an uploaded file for security and stability reasons.

Second, you are file-writing the uploaded data, which isn't necessary and you'll see why.

 

Now for your problem, you could use $_FILES with uploaded files to get information such as the source directory, remote file name, where the uploaded file is stored in /tmp or wherever your host puts them, and other sorts of useful data that you might need to use when handling file uploads.

 

Next, if you need to upload from a remote url you can either have the full url that the remote file is being uploaded from passed as a form input type, probably a hidden input type OR check the referer with PHP... if you want to add a little security, you could do both and ensure that they match up. But if you are grabbing the source of a remote file, why not use file_get_contents(), or if that is not possible, try cURL.

Link to comment
https://forums.phpfreaks.com/topic/239706-remote-uploading/#findComment-1231382
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.