KingOfHeart Posted April 11, 2010 Share Posted April 11, 2010 I want to create an option for them to either paste a link or upload. How can I have them select one, and disable the other. I know it has something to do with "radio" When it comes to uploading, I like to give a 1MB upload limit as well. Link to comment https://forums.phpfreaks.com/topic/198241-php-link-or-upload/ Share on other sites More sharing options...
andrewgauger Posted April 12, 2010 Share Posted April 12, 2010 Check with your host about file upload limits. <html> <head> <script language="javascript"> function formEnable(arg) { if (arg==1){ document.form_upload.filepicker_upload.disabled=false; document.form_upload.text_link.disabled=true; } if (arg==2){ document.form_upload.filepicker_upload.disabled=true; document.form_upload.text_link.disabled=false; } } </script> </head> <body> <form name="form_upload"> <input type="radio" name="radio_deliverymethod" onClick="formEnable(1)">File: <input type="file" name="filepicker_upload" disabled="disabled"><br> <input type="radio" name="radio_deliverymethod" onClick="formEnable(2)">Link: <input type="text" name="text_link" disabled="disabled"><br> </form> </body> </html> *tested* Link to comment https://forums.phpfreaks.com/topic/198241-php-link-or-upload/#findComment-1040182 Share on other sites More sharing options...
KingOfHeart Posted April 15, 2010 Author Share Posted April 15, 2010 Well what about 1000KB for now? The script works good so far. Now I want to have it upload the file if the upload radio is selected, if not I just want to return the file name of the link. Is more javascript required to figure out which one is enabled, and which one is disabled? Link to comment https://forums.phpfreaks.com/topic/198241-php-link-or-upload/#findComment-1042656 Share on other sites More sharing options...
andrewgauger Posted April 15, 2010 Share Posted April 15, 2010 Both of those topics are implemented in php. Have you set up a form handler in php? the form should have action="name.php" method="post" http://ro.php.net/manual/en/features.file-upload.post-method.php This explains what you need to do to handle the upload. You can set the limit to 1000KB by examining the $_FILES['userfile']['size'] if ($_FILES['userfile']['size']>1048576){ echo "File too big!"; } else { $uploaddir = './';//<----This is all I changed $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); echo '<pre>'; if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { echo "File is valid, and was successfully uploaded.\n"; } else { echo "Possible file upload attack!\n"; } } This example came from the same page: http://ro.php.net/manual/en/features.file-upload.post-method.php#94973 I also don't understand what you want to do with the link. Link to comment https://forums.phpfreaks.com/topic/198241-php-link-or-upload/#findComment-1042721 Share on other sites More sharing options...
KingOfHeart Posted April 15, 2010 Author Share Posted April 15, 2010 Will it know that the upload option was selected? A user could choose an upload, switch the radio to a link and then submit. So I want to make sure it knows which one is selected. Link to comment https://forums.phpfreaks.com/topic/198241-php-link-or-upload/#findComment-1042745 Share on other sites More sharing options...
andrewgauger Posted April 16, 2010 Share Posted April 16, 2010 The code is by no means complete, you should definitely check to see if the radio is selected. Validate EVERYTHING you can think of and then ask someone else to think of some more things to validate. I THINK javascript disabling an object prevents it from posting, but test it to find out. Link to comment https://forums.phpfreaks.com/topic/198241-php-link-or-upload/#findComment-1042767 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.