Warptweet Posted March 27, 2007 Share Posted March 27, 2007 Here is the BASE for my uploader code, which will be later heavily edited. It works perfectly, absolutely no problem. Although, how would I upload a file through it's direct source link on the internet OR from files on your computer? Here is my code. For this code, you can only upload from the location on your COMPUTER, but I need it to do that, AND be able to upload from a link on the internet. Thanks for any help! <?php function generate_rand($l){ $c= "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"; srand((double)microtime()*1000000); for($i=0; $i<$l; $i++) { $rand.= $c[rand()%strlen($c)]; } return $rand; } $uploaddir = "./"; $maxfilesize = 1048576; //1 megabyte $filename = $_FILES['file']['name']; $filesize = $_FILES['file']['size']; $filetmpname = $_FILES['file']['tmp_name']; $valid = array (".jpg",".gif",".png"); if ($filename) { $error = ""; if ($filesize == 0) { $error .= "The submitted file was invalid.<br />"; } $type = strtolower(strstr($filename, '.')); if (!in_array($type, $valid)) { $error .= "The submitted file was of invalid type.<br />"; } if ($filesize>$maxfilesize) { $error .= "The submitted file was larger than a Megabyte.<br />"; } $randnum = generate_rand(10); $randnum .= $type; $file_exists = true; while ($file_exists) { if (file_exists("$uploaddir$randnum")) { $randnum = generate_rand(10); $randnum .= $type; }else{ $file_exists = false; } } if ($error == "") { if (move_uploaded_file($filetmpname, "$uploaddir$randnum")) { chmod("$uploaddir$randnum", 0644); echo "Your file was successfully uploaded!<br />"; echo "<a href='".$uploaddir$randnum."'>Click here to go to your upload!</a>"; } else { echo "Your file could not be uploaded."; } }else{ echo $error; } }else{ echo "No file was uploaded"; } ?> Link to comment https://forums.phpfreaks.com/topic/44567-upload-from-link-instead/ Share on other sites More sharing options...
trq Posted March 28, 2007 Share Posted March 28, 2007 You can use copy to copy files from a url to your server providing url wrappers are enabled in your configuration. Link to comment https://forums.phpfreaks.com/topic/44567-upload-from-link-instead/#findComment-216464 Share on other sites More sharing options...
Trium918 Posted March 28, 2007 Share Posted March 28, 2007 Where is the code that calls the function generate_rand($l) ? Link to comment https://forums.phpfreaks.com/topic/44567-upload-from-link-instead/#findComment-216468 Share on other sites More sharing options...
Warptweet Posted March 28, 2007 Author Share Posted March 28, 2007 It's here $randnum = generate_rand(10); Right below the "You entered a file above 1 Megabyte" error message in the code. Link to comment https://forums.phpfreaks.com/topic/44567-upload-from-link-instead/#findComment-216511 Share on other sites More sharing options...
Trium918 Posted March 28, 2007 Share Posted March 28, 2007 There is a syntax in your code. echo "Testing output would not show up"; Link to comment https://forums.phpfreaks.com/topic/44567-upload-from-link-instead/#findComment-216521 Share on other sites More sharing options...
trq Posted March 28, 2007 Share Posted March 28, 2007 There is a syntax in your code. echo "Testing output would not show up"; What are you talking about? Link to comment https://forums.phpfreaks.com/topic/44567-upload-from-link-instead/#findComment-216533 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.