Download from server not working

I am trying to download files from one of my servers to another and here is my code the file downloads like if I put
name=“death”
url=“http://deathcrow.altervista.org/death.html

The file downloads in the directory death/death.html however when i look at the file it is blank :confused:

<form method="post">
 <input type="text" name="name" placeholder="name"> <br>
 <input type="text" name="url" placeholder="url"> <br>
 <input type="submit" name="submit" value="upload">
</form>			

<?
if(isset($_POST['submit'])){
 ignore_user_abort();
 $Fname = $_POST['name'];
 $url = $_POST['url'];

 mkdir($Fname);


 $name = basename($url);
 file_put_contents("$Fname/$name", file_get_contents($url));

$check = file_exists("$Fname/$name")
 if($check){
  echo 'Success';
 } else{
  echo 'Something went wrong';
 }
}
?>`

Can someone please help?

Hi joseph_williamson_de welcome to the forum

Well, if file_put_contents is working as far as creating a file, the problem is most likely with getting the content.

Maybe test with is_file before attempting to get it’s contents?

http://php.net/manual/en/function.is-file.php

BTW 20 minutes isn’t all that long a time, is it?

As is whether it works or not that script is opening a huge security hole.

1 Like

Im not so worried about security because its a server unavalible to the public only me and a few admins can see the page and access its contents

how would you suggest going about this exactly? and i am a bit unpatient I have spent the good part of an hour trying to get this to work

I would pass the user supplied values to a function that checked to see if everything was OK with them. Then either return the values or a false.

Then I would put the file code stuff inside an if that wouldn’t run if the false was returned.

Even if the folder is not “public” and there are only “a few” users, I would lock down the permissions and not allow certain (especially non-text) files to be written to it.

For that matter, even if it was only me and only on my localhost I would code in some safe guards.
I can trust myself to not try anything nefarious, but I can’t trust myself to never make a mistake…

as it is like i provided a real example i have a file on my server at this link http://deathcrow.altervista.org/death.html

I need to get that file on this server through this code now how do i achieve this cause I am baffled

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.