Oliverkahn Posted July 26, 2015 Share Posted July 26, 2015 i wrote a script to upload files via url but its not working fine. wen i import the file, it creates the file on the server but refuses to write to it and the file size remains 0.00 byte. below is my code. php <?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" or $ext=="jpeg" or $ext=='apk' or $ext=='jar' or $ext=='mp4' or $ext=='mp3' or $ext=='avi' or $ext=='3gp' or $ext=='exe' or $ext=='zip' or $ext=='tar' or $ext=='jad'){ //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 <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>[ /code] Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted July 26, 2015 Share Posted July 26, 2015 (edited) Try changing your form? <form action="uploader.php" method="post" enctype="multipart/form-data"> Upon further review, I see you are posting the URL and not the file, so the above isn't applicable. Why do you wish to do it your way? Also, you really want to allow the user to upload .exe files? Edited July 26, 2015 by NotionCommotion Quote Link to comment Share on other sites More sharing options...
Oliverkahn Posted July 26, 2015 Author Share Posted July 26, 2015 i want to implement file importing via url i want any type of file to be imported... the script didn't work pls can you help me review it? Quote Link to comment Share on other sites More sharing options...
NotionCommotion Posted July 26, 2015 Share Posted July 26, 2015 It works for me. Maybe some sort of folder permission issue? Quote Link to comment Share on other sites More sharing options...
Oliverkahn Posted July 26, 2015 Author Share Posted July 26, 2015 hmm...so what do i do? i have allow all permission i also chmode it to 777 Quote Link to comment Share on other sites More sharing options...
mac_gyver Posted July 26, 2015 Share Posted July 26, 2015 file_get_contents($url) the settings that allow statements to read a file using a url are usually turned off. do you have php's error_reporting set to E_ALL and display_errors set to ON so that php would be reporting and display any errors it detects? Quote Link to comment Share on other sites More sharing options...
Oliverkahn Posted July 26, 2015 Author Share Posted July 26, 2015 i have enable it but no error was reported.. pls help me Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.