Closed Thread Icon

Topic awaiting preservation: Download/Upload file with URL Pages that link to <a href="https://ozoneasylum.com/backlink?for=12831" title="Pages that link to Topic awaiting preservation: Download/Upload file with URL" rel="nofollow" >Topic awaiting preservation: Download/Upload file with URL\

 
Author Thread
Sam
Bipolar (III) Inmate

From: Belgium
Insane since: Oct 2002

posted posted 07-24-2003 13:32

Hi All,

Is it possible to upload a certain file to a website just by entering the URL of the file on a webpage? This way you get a copy of the file (image, ...) on the internet (on another web page) on your own webserver without needing to download and upload it yourself.

Example:
1)Site A (www.siteA.com) has an image with the following url: http://www.siteA.com/image01.jpg
2)Site B (www.siteB.com) has a page containing a form where you can submit a link to a file.
3) If you submit the url of the image on site A on the page of site B you get an image on site B with the url http://www.siteB.com/image01.jpg and this is a copy of the file on site A.

--> Is this possible?

Sam

Skaarjj
Maniac (V) Mad Scientist

From: :morF
Insane since: May 2000

posted posted 07-24-2003 14:04

Which programming language were you thinking of using? I'd personally use PHP for this (then again I'd personally use PHP for almost everything ). You could do it by getting the script to open up the file, store it's contents and write them into a file using the same file name and extension type.

I'll try and come up with something soon.

Sam
Bipolar (III) Inmate

From: Belgium
Insane since: Oct 2002

posted posted 07-24-2003 14:40

Yes I was thinking about PHP to do achieve this but my knowledge of PHP is not that big.

I think there are also some limitations because not every site allows that you access it's content from another site, isn't it?

Anyway, thanks!

Sam

Skaarjj
Maniac (V) Mad Scientist

From: :morF
Insane since: May 2000

posted posted 07-24-2003 14:41

Hang on...are you thinking of doing this from a site that isn't yours to a site that is yours? that's stealing mate...and I won't help you do that.

Sam
Bipolar (III) Inmate

From: Belgium
Insane since: Oct 2002

posted posted 07-24-2003 14:49

Yes, I think you could (ab)use it this way but that's not my intention.

It was not my idea to put all this copied stuff on a public site it's just some tool I could use and I was wondering if it is possible.

Sam

Skaarjj
Maniac (V) Mad Scientist

From: :morF
Insane since: May 2000

posted posted 07-24-2003 14:51

Well...it is entirely possible to do it...I'm a bit busy right now, but I'll write up a hack for it sometime soon.

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 07-24-2003 16:42

you'll hast have to grab the url from the form, fopen() it, read it, extract it's filename, store it, and you're set.

Implementation is left as an exercise for the reader.

Hint: fopen()'s manual page should tell you all you need to know.

Sam
Bipolar (III) Inmate

From: Belgium
Insane since: Oct 2002

posted posted 07-25-2003 11:36

Nice excercise, indeed.

I have a working PHP script with files in the same directory as the PHP file. The only thing is that I'm having trouble with the "/". The server doesn't find the files specified with a "/". Propably because it needs "\" instead of "/". I'm sure you guys know the function I need to solve this little problem.

Thanks,

Sam


Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 07-25-2003 14:20

Sorry?

if you start your files with /, it's no miracle the server can't find them, for it's looking it it's root directory, not the current one.
The current one would be ./ .
\ and / don't matter the tiniest bit on windows... you can use them interchangably.

Sam
Bipolar (III) Inmate

From: Belgium
Insane since: Oct 2002

posted posted 07-25-2003 15:36

Nope, all the urls I submit start with "http://".

I'm now trying to read the remote file into a variable so I can write a copy to my site.
Reading files with fread() is only possible for local files but not for remote files.

This is what I'v got in the PHP script:

code:
$url = addslashes($url);
IF ($fileurl = fopen("$url","rb"))
{
rewind($fileurl);
$filecontent = fread($fileurl, filesize($url));
$copy = fopen("file01.jpg","wb");
fwrite($copy,$filecontent);
fclose($copy);
fclose($fileurl);
print "File created!";
}
else
{
print "Error!";
}



This script only works for local files.
Any hints to retrieve the file size of a remote file?

Sam

[This message has been edited by Sam (edited 07-25-2003).]

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 07-25-2003 21:01

well, it should work for full urls (like http://www.example.tld/myfile),
but of course it is possible that http-access has been disabled in your installation of php.
Throw up a file containing
<?php
phpinfo();
?>
and tell us what it says, and we'll see more.

Sam
Bipolar (III) Inmate

From: Belgium
Insane since: Oct 2002

posted posted 07-28-2003 11:21

A lot of information there.
I can't find any parameter like http-access.
I'm using PHP Version 4.3.0.
Any other parameter or settings I should pay attention to?

Sam

Tyberius Prime
Paranoid (IV) Mad Scientist with Finglongers

From: Germany
Insane since: Sep 2001

posted posted 07-28-2003 13:27

I'll only know when I look at it.
so post a link alread ;-)

Sam
Bipolar (III) Inmate

From: Belgium
Insane since: Oct 2002

posted posted 07-28-2003 14:22

Never mind, here's the solution!

code:
<?PHP
$filename = substr(strrchr($url,"/"),1);
$url = addslashes($url);
// Copy file on local server
IF ($fileurl = fopen("$url","rb"))
{
rewind($fileurl);
while(!feof($fileurl))
{
$filecontent = $filecontent . fread($fileurl, 1024);
}
$copy = fopen("$filename","wb");
fwrite($copy,$filecontent);
fclose($copy);
fclose($fileurl);
print "File $filename created";
}
else
{
print "Error!";
}
?>

Thanks for the tips.

Sam

PS: I am not going to post a link to my phpinfo() file because it contains my (ftp) password!
(I've put it in a secure area now)




[This message has been edited by Sam (edited 07-28-2003).]

lobotomy
Nervous Wreck (II) Inmate

From:
Insane since: Aug 2003

posted posted 08-10-2003 04:58

What OS are you using? Do you have an ftp client? Windows might use ws-ftp. I use gFTP in Linux an this is what I do.

Open gftp and logon to my host.
Then I point the "Local" window to the download directory. NOTE this must be an http address as gFTP will not let me log on to 2 ftp servers at once.

Lets say I want to transfer a file from the latest test kernel (linux-2.4.6-test3) I would put this in the address bar for the local panel: http://www.kernel.org/pub/linux/kernel/v2.6/
Then I can select a file and hit the -> arrow and it transferrs the file directly to my web site.


« BackwardsOnwards »

Show Forum Drop Down Menu