/    Sign up×
Community /Pin to ProfileBookmark

fileupload fails

i am trying to upload a file to the server, i found basic tutorials to do so, but moveuploaded file fails
i tried to debug the script and it appears that all the variables are correct, the file path is valid on the server, and the tmpfile path and name appear correct, this is the php i am using

[code=php]<?php
foreach($_POST as $key => $value){

if($value != “”){
$message .= $key. ” ——— ” . $value. “n” ;

echo $key . ” —– ” . $value. “<br>”;
}else{
$error = true;

}
}
foreach($_FILES as $myfile => $xxx){
foreach($xxx as $uploadedfile => $name){
echo $uploadedfile . ” —– ” . $name . “<br>”;
}
}
$target_path = getcwd(). “/upload/”;

echo $_FILES[“uploadedfile”][“tmp_name”].”<br>”;
echo exec(‘whoami’);
chmod($_FILES[“uploadedfile”][“name”],0777);
echo substr(sprintf(‘%o’, fileperms($_FILES[“uploadedfile”][“tmp_name”])), -4).”<br>”;

// ulink($_FILES[“uploadedfile”][“tmp_name”]);

echo $_FILES[“uploadedfile”][“name”].”<br>”;

$target_path = $target_path . basename( $_FILES[‘uploadedfile’][‘name’]);
// copy($_FILES[“uploadedfile”][“tmp_name”], $target_path . $_FILES[“uploadedfile”][“name”]);
echo $target_path.”<br>”;
if(move_uploaded_file($_FILES[‘uploadedfile’][‘tmp_name’], $target_path)) {
echo “The file “. basename( $_FILES[‘uploadedfile’][‘name’]).
” has been uploaded”;
} else{
echo “There was an error uploading the file, please try again!”;
}
?>[/code]

i have 2 file inputs in a htm page and get a return like

[QUOTE]

MAX_FILE_SIZE —– 1000000
name —– bin_file.txt
type —– text/plain
tmp_name —– /tmp/phpMtU95N
error —– 0
size —– 4135
name —–
type —–
tmp_name —–
error —– 4
size —– 0
/tmp/phpMtU95N
apache0600
bin_file.txt
/home/***/castagna/upload/bin_file.txt
There was an error uploading the file, please try again!

[/QUOTE]

only 1 file input filled

i do not find the tmpfile in the server tmp folder
the chmod does not appear to change the permissions, maybe apache is not authorised to do so?

if found this in a thread here, courtsey //./
<?php echo phpinfo(); ?>

which returns
way too much to post here,
but i can post any parts that may help

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@JunkMaleSep 14.2009 — I would suggest you look at the sticky at the top of the forum that covers this upload to the server and it is something that you can easily build on.

Your upload could be failing for a number of reasons, it could be a wrong path your trying to get or set or it could be that the file is too big for the max upload.
Copy linkTweet thisAlerts:
@toicontienSep 14.2009 — PHP might not have permissions to save the file in the location you want.
Copy linkTweet thisAlerts:
@JunkMaleSep 14.2009 — Looking at the script, your attempting to chmod a file reference that has not yet been moved...

I suggest that you follow the example of file uploads as written by Bokeh here. Which is a very good tutorial that you can build upon.
×

Success!

Help @westconn1 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.5,
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: @Yussuf4331,
tipped: article
amount: 1000 SATS,

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

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...