/    Sign up×
Community /Pin to ProfileBookmark

loading image

How do I do so that the image (loading.gif) displayed while I are uploading a file

[code=php]<?php
if(isset($_POST[‘frm_upload’]))
{
if(is_uploaded_file($_FILES[‘frm_file’][‘tmp_name’]))
{
$filetypes = ‘.php, .htm, .html’;

$original_name = $_FILES[‘frm_file’][‘name’];
$file_extension = strrchr(strtolower($original_name), ‘.’);

$types = explode(‘, ‘,strtolower($filetypes));

if(in_array($file_extension,$types))
{
echo “You can’t upload php, htm and html filetypes “;
$check_filename = “false”;
}
else
{
$check_filename = “true”;
}

if ($_FILES[‘frm_file’][‘size’] > 50000000)
{
echo “The file can max be 50mb.<br>”;
$check_filesize = “false”;
}
else
{
$check_filesize = “true”;
}

if($check_filename == “true” && $check_filesize == “true”)
{
copy($_FILES[‘frm_file’][‘tmp_name’], $_POST[‘path’].$_FILES[‘frm_file’][‘name’]);

echo “You have uploaded the file {$_FILES[‘frm_file’][‘name’]}.<br>”;
}
}
}
?>
<form method=”post” action=”up.php” enctype=”multipart/form-data”>

<input type=”file” name=”frm_file”><br>
<select name=”path”>
<option value=”0192837465/<?php echo $_SESSION[‘sess_id’]; ?>/”>Your folder</option>
</select>
<input type=”submit” name=”frm_upload” value=”Upload”>

</form>[/code]

I’m from Sweden
sorry for my bad English

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@bourkey08Oct 19.2008 — put this just before the part of the script that uploads the file

echo("<img id='loading' src='loading.gif'>");
Copy linkTweet thisAlerts:
@ariellOct 19.2008 — Since php scripts echo "anew" not before they return, the easiest way is to set up some JS on the client side. Namely a function that explicitly sets a (prior hidden) progress image visible (you could connect this function with the onclick event of the upload button).

Now, depending on whether you redirect the user to another page or not, you won't or will set this image invisible (if you re-direct this is certainly not necessary).

Keep in mind that this approach is not working, if JS is blocked on the client side.

Best from the south.
Copy linkTweet thisAlerts:
@scrapisauthorOct 19.2008 — Can anyone code it for me?
Copy linkTweet thisAlerts:
@ariellOct 19.2008 — At least to the extent of MY understanding, this is a coding forum, not a job board. Look, many of us make a LIVING of writing code for others, so what do you expect? Wasting the few bucks one can earn in this world?
Copy linkTweet thisAlerts:
@jayapalchandranOct 20.2008 — have a hidden iframe to which your form posts the values. let the iframe src be the server side script which processes the uploaded content. the iframe can be insivible ... so when you post a form the page wont reload and this is what makes your dream come true...

before you submit the form display a processing.gif

and once the file is completely uploaded [that is the script in the iframe has completed its process use javascript form the iframe and call the parent object to turn off the image...

give it a shot and you will learn a lot...

this method is the best way to upload files like ajax...

adios...
Copy linkTweet thisAlerts:
@bourkey08Oct 20.2008 — This is how i would do it.

Note: this may not work if the output is buffered by the browser
[code=html]<div id='par'>
<img id='loading' src='loading.gif' width=100 height = 100>
</div>
<?php
//upload code here
flush()
Sleep(15);
?>
<!-- remove image-->
<script language='javascript'>
var child = document.getElementById('loading');
var parent = document.getElementById('par');
parent.removeChild(child);
</script>
[/code]
Copy linkTweet thisAlerts:
@scrapisauthorOct 20.2008 — OK, but if I want this code to be displayed while I upload a file

[code=html]<script type="text/javascript">
var bar1= createBar(300,15,'white',1,'black','orange',85,7,3,"");
</script>[/code]
×

Success!

Help @scrapis spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...