/    Sign up×
Community /Pin to ProfileBookmark

hi got this problem. i have a script for uploading files with php but it doesn’t work I was told to put this code in
[B]if(isset($HTTP_POST_FILES[‘file’]) && $HTTP_POST_FILES[‘file’] != “”) {
$_file_ = $HTTP_POST_FILES[‘file’];
}else{
$_file_ = “”;
} [/B]

which would replace this line
[B]$_file_ = $HTTP_POST_FILES[‘file’];[/B]

the error I am getting is
[B]Notice: Undefined index: file in c:phpdev5wwwtmppw547ge9sp.php on line 18.[/B]
lin 18 is
[B]$_file_ = $HTTP_POST_FILES[‘file’];[/B]

Here is the full script
<?php
// ———————————————
// Pure PHP Upload version 1.1
// ——————————————-
if (phpversion() > “4.0.6”) {
$HTTP_POST_FILES = &$_FILES;
}
define(“MAX_SIZE”,300000);
define(“DESTINATION_FOLDER”, “./uploads”);
define(“no_error”, “sucsess.php”);
define(“yes_error”, “faild.php”);
$_
accepted_extensions_ = “”;
if(strlen($_
accepted_extensions_) > 0){
$_
accepted_extensions_ = @explode(“,”,$_accepted_extensions_);
} else {
$_
accepted_extensions_ = array();
}
$_
file_ = $HTTP_POST_FILES[‘file’];
if(is_uploaded_file($_
file_[‘tmp_name’]) && $HTTP_POST_FILES[‘file’][‘error’] == 0){
$errStr = “”;
$_
name_ = $_file_[‘name’];
$_
type_ = $_file_[‘type’];
$_
tmp_name_ = $_file_[‘tmp_name’];
$_
size_ = $_file_[‘size’];
if($_
size_ > MAX_SIZE && MAX_SIZE > 0){
$errStr = “File troppo pesante”;
}
$_
ext_ = explode(“.”, $_name_);
$_
ext_ = strtolower($_ext_[count($_ext_)-1]);
if(!in_array($_
ext_, $_accepted_extensions_) && count($_accepted_extensions_) > 0){
$errStr = “Estensione non valida”;
}
if(!is_dir(DESTINATION_FOLDER) && is_writeable(DESTINATION_FOLDER)){
$errStr = “Cartella di destinazione non valida”;
}
if(empty($errStr)){
if(@copy($_
tmp_name_,DESTINATION_FOLDER . “/” . $_name_)){
header(“Location: ” . no_error);
} else {
header(“Location: ” . yes_error);
}
} else {
header(“Location: ” . yes_error);
}
}
?>
<html>
<head>

</head>

<body>
<form name=”form1″ enctype=”multipart/form-data” method=”post” action=””>
<input type=”file” name=”file”>
</form>
</body>
</html>

Please help
Thanks

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@SpectreReturnsMay 21.2005 — Well, the error indicates that you haven't submitted your form.
Copy linkTweet thisAlerts:
@purplehaze203authorMay 21.2005 — This happens as soon as the page loads you don't get chance to submit the form the error just comes up.
×

Success!

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