|
-
Jul 11th, 2008, 07:08 AM
#1
Thread Starter
Hyperactive Member
Display 'uploading' after use pushes upload button.
Hello, I have the below script that uploads a file via PHP. I know you can't directly add a progress bar with PHP, but is there a way to at least have it say 'uploading' after the user clicks 'upload file'...but before it actually copies?
Code:
<html>
<title>Welcome to DadsSendsIt!</title>
</html>
<?php
$action = $_POST["action"];
$max_size = "67108864"; // Max size in BYTES (1MB)
$rand_folder = str_rand(15, 'alphanum');
echo "
<b>Use the below Uploader to upload the file. Uploads can take a few minutes for large files. Once uploaded, you will be shown the link to the file. From there, you may copy and paste it into an email to send.</b></br></br>
<b>Uploader</b><br>
<form action='upload with random.php' method=post enctype='multipart/form-data'>
File (max size: $max_size bytes/".($max_size/1024)." kb):<br>
<input type='file' name='filename'><br>
<input type='hidden' name='action' value='upload'>
<input type='submit' value='Upload File'>
</form>";
if ($action == 'upload')
{
if ($_FILES["filename"]["size"] > $max_size) die ("<b>File too big! Try again...</b>");
echo "DA";
mkdir("./uploads/".$rand_folder);
copy($_FILES["filename"]["tmp_name"],"./uploads/".$rand_folder."/".$_FILES["filename"]["name"]) or die("<b>Unknown error!</b>");
echo "<b>File Uploaded. </b>"; // for debug --> $filename --> ".$destination."/".$filename_name."</h2>";
echo "http://www.dadsftp.com/uploads/".$rand_folder."/".$filename_name."</br>";
$urlvar = "http://www.dadsftp.com/uploads/".$rand_folder."/".$filename_name;
echo "<a href=\"$urlvar\">Right Click here and Copy Shortcut</a>";
}
?>
I tried placing it where it says "echo "DA";" but it doesn't echo it until after the file is uploaded.
Code:
If LostAngel.Tag = "Programming" then
LostAngel.Caption = "Awake"
Else
LostAngel.Caption = "Dreaming of Code"
End If
-
Jul 12th, 2008, 01:36 AM
#2
Re: Display 'uploading' after use pushes upload button.
you are going to need to use javascript for that. This thread needs to be moved to Javascript Forum ----> thanks.
My usual boring signature: Something
-
Jul 13th, 2008, 05:48 PM
#3
Re: Display 'uploading' after use pushes upload button.
It's hardly worth the trouble because when the upload button is clicked, the form will be submitted and the page will disappear as it posts and uploads, so depending on the behavior of the users browser, they might not see the uploading message for more than a split second.
Anyway all that is needed is a simple javascript to do it, for example:
add this span tag after your form (or wherever you want the message displayed:
<span id="uploaderMsg"> </span>
Then add this javascript into your page (preferrably in the <head> section)
<script type="text/javascript">
function showMsg()
{
document.getElementById('uploaderMsg').innerHTML = "Uploading please wait...";
}
</script>
Also add this to the <form> tag: onsubmit="showMsg()" so the <form> tag would look like
<form onsubmit="showMsg()" action='upload with random.php' method=post enctype='multipart/form-data'>
So basically you have a Span element, which will contain the uploader msg, then you have the piece of javascript which sets the content of the span tag to 'Uploading please wait...', then of course you need to call this script when the upload starts, so you put the onsubmit="showMsg()" in the form tag. It could also be done by calling the script in the click event of the upload button for example
<input onclick="showMsg()" type='submit' value='Upload File'>
-
Jul 14th, 2008, 08:20 AM
#4
Thread Starter
Hyperactive Member
Re: Display 'uploading' after use pushes upload button.
Alright guys, thank you. I do have one more question on my upload script. I have it echo the location of the uploaded file after it uploads with the following mailto address:
echo "<a href=\"mailto:?body=$urlvar\">Click here to open new email message with link in the body.</a>";
$urlvar i the location of the file. Is i possible to have it look at my $urlvar, and replace any spaces with %20?
Code:
If LostAngel.Tag = "Programming" then
LostAngel.Caption = "Awake"
Else
LostAngel.Caption = "Dreaming of Code"
End If
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|