Created
February 18, 2019 14:31
-
-
Save codeonion/2c4707b6467dea7f7986f70d87eaeb56 to your computer and use it in GitHub Desktop.
PHP: File uploading Basic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//blog.theonlytutorials.com | |
//author: agurchand | |
if($_POST){ | |
//get the url | |
$url = $_POST['url']; | |
//add time to the current filename | |
$name = basename($url); | |
list($txt, $ext) = explode(".", $name); | |
$name = $txt.time(); | |
$name = $name.".".$ext; | |
//check if the files are only image / document | |
if($ext == "jpg" or $ext == "png" or $ext == "gif" or $ext == "doc" or $ext == "docx" or $ext == "pdf"){ | |
//here is the actual code to get the file from the url and save it to the uploads folder | |
//get the file from the url using file_get_contents and put it into the folder using file_put_contents | |
$upload = file_put_contents("uploads/$name",file_get_contents($url)); | |
//check success | |
if($upload) echo "Success: <a href='uploads/".$name."' target='_blank'>Check Uploaded</a>"; else "please check your folder permission"; | |
}else{ | |
echo "Please upload only image/document files"; | |
} | |
} | |
?> | |
<html> | |
<head><title>Theonlytutorials - Simple File Upload from URL Script!</title></head> | |
<body> | |
<h3>Theonlytutorials.com - Very Simple File Upload from URL Script!</h3> | |
Paste the url and hit enter! | |
<form action="" method="post"> | |
Your URL: <input type="text" name="url" /> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment