473,378 Members | 1,209 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Copying remote files using fopen and fwrite

60
i wanted a remote file uploader in php, i mean a form where you send the URI of a file on other web and the script saves it locally.

i tried:

[PHP]<? if(empty($_POST)){ ?>
<html>
<body>
<form method=POST>
<b>URL del Archivo </b>
<input type=text name=uri><br>
<input type=text name=srv>
<input type=submit value=Descargar>
</form>
</body>
</html>
<?
}else{
$file = $_POST['uri'];

$ges = fopen($file, "r");
$ges = fwrite($ges, "\.\/some.thing");
}
?>[/PHP]

1. I know there's something wrong but don't know what

2. How can i store it with the original name and extension ?


thanks
May 22 '07 #1
3 6447
pbmods
5,821 Expert 4TB
Changed thread title to better match contents.

Expand|Select|Wrap|Line Numbers
  1. $ges = fopen($file, "r");
  2. $ges = fwrite($ges, "\.\/some.thing");
  3. }
  4. ?>
1. I know there's something wrong but don't know what

2. How can i store it with the original name and extension ?
1. You're opening a file with read access ('r'), then you try to write to it. Nope. :P

http://php.net/fopen

2. You want to do something like this:
Expand|Select|Wrap|Line Numbers
  1. $file = basename($_POST['uri']);
  2. copy("/path/to/source/$file", "/path/to/dest/$file");
  3.  
http://php.net/copy
May 23 '07 #2
pplers
60
[PHP]<? if(empty($_POST)){ ?>
<html>
<body>
<form method=POST>
<b>URL del Archivo </b>
<input type=text name=uri><br>
<center><input type=submit value=Descargar></center>
</form>
</body>
</html>
<?
}else{
$uri = $_POST['uri'];
$file = basename($_POST['uri']);
copy("$uri", "$file");
echo $file."<br>".$uri;
}
?>[/PHP]

ok, right ??
May 23 '07 #3
pbmods
5,821 Expert 4TB
ok, right ??
Looks pretty good to me. Note that you will be copying the file to the same directory as your script.

If this doesn't work (I can't remember if copy allows you to use URLs or not), try using file_put_contents instead.
May 23 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: tisgrim | last post by:
Right...have loads of C++, SQLServer experience but about 5 minutes of JavaScript, ASP etc. Spent a frustrating 2 days deciding the best way to get some data from a SQL database, then cached in...
2
by: Robizzle | last post by:
I'm working on a very simple script that logs the ip address, time of hit, and os/browser information and currently it works every time. The problem is getting the script included into my html...
13
by: Blue | last post by:
Hi , Can any one please let me explain me the diffrences between "open"/ "fopen" or "read"/"fread" or "write/fwrite". I know that "open" /"read" / "write" are system calls and "fopen"...
7
by: Olaf \El Blanco\ | last post by:
/* It look for a last name... That's work OK. If 'del' is 1, after search it will delete I want to put the field valid at NOT_VALID but even fwrite return 1, it never copy anything */ void...
5
by: m.topczewski | last post by:
Hello, I'm a beginner in c++, i have to write a program that will take couple of segments from one wave file, and store them in another wave file to be played back later. Here's the code i have...
12
by: Sankar | last post by:
Dear all, I am programming in Linux , wherein I need to know a couple of things. 1) Does an API exist that can copy file onto another file ( an API equivalent of 'cp') ? 2) Is there an API...
18
by: mike3 | last post by:
Hi. I have an interesting problem. The C program presented below takes around 12 seconds to copy 128 MB of data on my machine. Yet I know the machine can go faster since a copying done at a...
0
by: nothing1 | last post by:
My script is below. And it worked perfectly until this morning when i got up and went of to try it it didnt work anymore. The code stayed the same so im sure its not that. I think it has something to...
4
by: pcfreak30 | last post by:
ok, i probably have not been registered here long, but i am no noob. I am very experienced in php, but the php cli is a bit of new territory for me. I am trying to create a simple little script...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.