/    Sign up×
Community /Pin to ProfileBookmark

File Upload Help

The following script refuses to upload files to the appropriate folder and I can’t figure out why. There are no errors that display. Anyone have any suggestions on what I did wrong?

[code=php]if(isset($_POST[‘upload’])) {
$upload_directory = “../uploads/” . $section . “/”;

if(!isset($_FILES[‘file_upload’][‘name’])) {
$file_message = “Select File To Upload”;
} else {
$ext = findextension($_FILES[‘file_upload’][‘name’]);
//create unique name
$now = 1;
while(file_exists($uploadFilename = $upload_directory . $now . $_FILES[‘file_upload’][‘name’]))
{
$now++;
}
if(move_uploaded_file($_FILES[‘file_upload’][‘tmp_name’], $uploadFilename)) {
$file_message = “File Uploaded”;
} else {
$errors = array(1 => ‘php.ini max file size exceeded’,
2 => ‘html form max file size exceeded’,
3 => ‘file upload was only partial’,
4 => ‘no file was attached’);
$error = $_FILES[‘file_upload’][‘error’];
$upload_message = $errors[$error];
}
}
}// end of upload[/code]

to post a comment
PHP

4 Comments(s)

Copy linkTweet thisAlerts:
@stephan_gerlachJun 07.2010 — I would first check that the path is correct.

[code=php]
if(isset($_POST['upload'])) {
$upload_directory = "../uploads/" . $section . "/";
echo $upload_directory;
exit;
}
[/code]


if that is correct then I would check the FILES array for any problems

[code=php]
if(isset($_POST['upload'])) {
$upload_directory = "../uploads/" . $section . "/";
print_r($_FILES);
exit;
}
[/code]


If that doesn't help post again
Copy linkTweet thisAlerts:
@NtrimgsauthorJun 07.2010 — The path appears correct. Here is the folder hierarchy:

-uploads

-19

- administration

- upload_script.php

So the path I have is: ../uploads/19/

Here is the file array when I attempted to upload:

Array ( [file_upload] => Array ( [name] => Penguin.pdf [type] => application/pdf [tmp_name] => /usr/local/pem/vhosts/167276/tmp/phpP3tj23 [error] => 0 [size] => 316478 ) )
Copy linkTweet thisAlerts:
@SrWebDeveloperJun 07.2010 — Always use FULL PATH when using move_uploaded_file() or file_exists(). :rolleyes:
Copy linkTweet thisAlerts:
@NtrimgsauthorJun 07.2010 — Hey it worked! ?
×

Success!

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