/    Sign up×
Community /Pin to ProfileBookmark

Upload proccess help

Hi All,

I know i am bugging you cause im a noob with php, i would like to integrate a process bar with the code, but i dont know how or where to look. Can somebody please help?

[code=php]<form action=”<?php echo $_SERVER[‘PHP_SELF’];?>” method=”post” enctype=”multipart/form-data” name=”file_upload”>
<input type=”file” name=”file” id=”file”>
<input type=”hidden” name=”execute” id=”execute”>
<input type=”submit” name=”Submit” id=”Submit” value=”Submit”>
</form>
<?php
if (isset($_POST[‘execute’])) {

$filename = $_FILES[“file”][“name”];
$file_basename = substr($filename, 0, strripos($filename, ‘.’));
$file_ext = substr($filename, strripos($filename, ‘.’));
$filesize = $_FILES[“file”][“size”];

if (($file_ext == “.jpg” || $file_ext == “.png” || $file_ext == “.zip” || $file_ext == “.rar” || $file_ext == “.gif” || $file_ext == “.pdf”) && ($filesize < 2500000)) {
$newfilename = md5(time() . $file_basename) . $file_ext;

if (file_exists(“uplo@ds_dir/” . $newfilename)) {
$error = “You have already submitted this file.”;
} else {
move_uploaded_file($_FILES[“file”][“tmp_name”], “uplo@ds_dir/” . $newfilename);
echo “File uploaded successfully.”;
}
} elseif (empty($file_basename)) {
$error = “Please select a file to upload.”;
} else {
$error = “Only jpg, png, zip, rar, gif and pdf files can be submitted.”;
unlink($_FILES[“file”][“tmp_name”]);
}
}
?>/PHP]

Many Thanks!

to post a comment
PHP

7 Comments(s)

Copy linkTweet thisAlerts:
@ryanlundJun 29.2009 — Sorry, i have not read your code, but you would like to include a process bar with the upload right?? (so that it shows how much the user has uploaded etc). If this is the case it cannot be done with PHP, check out jQuery, it has some great plugins such as the one click upload plugin (which if i remember rightly can create a progress bar). Have a look around google, im sure you will find something =)
Copy linkTweet thisAlerts:
@JunkMaleJun 30.2009 — Yes you can, its a question of coding it.
Copy linkTweet thisAlerts:
@ryanlundJun 30.2009 — PHP is server side, there is no way it can do a progress bar simply for the fact its animated..
Copy linkTweet thisAlerts:
@JunkMaleJun 30.2009 — Yes you can, I wrote a script that did the revers on the server, did not allow the file to become available until it had uploaded.

Use AJAX to perform the upload and the query of serverside script to return the file length, when you code for it, you can produce a progress bar that can be expressed as a percentage.
Copy linkTweet thisAlerts:
@YooNetauthorJun 30.2009 — Can you maybe share it cause i have no idea to code javascrip
Copy linkTweet thisAlerts:
@JunkMaleJun 30.2009 — I wrote a script in PHP that simply returned the file size, use AJAX to request the filesize from that script.

Then you use another AJAX object to upload the file through "post"

Its simple enough and the subject has been covered on this site many time, all you need to do is look up AJAX form posting.
Copy linkTweet thisAlerts:
@ryanlundJun 30.2009 — Yes like i said in my post, i can not be done using php ALONE. Why does nobody read things properly these days. JS would be required - not rocket science is it guys.
×

Success!

Help @YooNet 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.13,
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,
)...