Jump to content

php link or upload


KingOfHeart

Recommended Posts

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

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.