/    Sign up×
Community /Pin to ProfileBookmark

Hi, I need help, I am trying to make a small form so that customer can upload a file to a folder in the site, but I cant seem to make this work, any help would be great:

I am trying just to upload a file to a site, I made a small form too upload with:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>

<html xmlns=”http://www.w3.org/1999/xhtml“>

<head>

<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″ />

<title>File Upload Form</title>

</head>

<body>

This form allows you to upload a file to the server.<br>

<form action=”getfile.php” method=”post”><br>

Type (or select) Filename: <input type=”file” name=”uploadFile”>

<input type=”submit” value=”Upload File”>

</form>

</body>

</html>

Then I made a php file to process it:

<!DOCTYPE html PUBLIC “-//W3C//DTD XHTML 1.0 Transitional//EN” “http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd“>

<html xmlns=”http://www.w3.org/1999/xhtml“>

<head>

<title>Process Uploaded File</title>

</head>

<body>

<?php

move_uploaded_file ($_FILES[‘uploadFile’] [‘tmp_name’],

“../uploads/{$_FILES[‘uploadFile’] [‘name’]}”)

?>

</body>

</html>

I am not trying to use the database, just want to let customer upload a file that goes into a folder. This is the errors I get:

[23-Jan-2008 09:44:10] PHP Notice: Undefined index: uploadFile in /usr/home/joesproduce.com/private/getfile.php on line 9
[23-Jan-2008 09:44:10] PHP Notice: Undefined index: uploadFile in /usr/home/joesproduce.com/private/getfile.php on line 10

to post a comment
PHP

6 Comments(s)

Copy linkTweet thisAlerts:
@here-to-helpJan 23.2008 — try the enctype...it is required for uploads:

[code=html]<form action="" method="post" enctype="multipart/form-data">[/code]
Copy linkTweet thisAlerts:
@momarkeyauthorJan 23.2008 — First thank you for help, seem to help a little, but still get error, a new one:

[23-Jan-2008 10:24:41] PHP Warning: move_uploaded_file(htdocs/uploads/flower3.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /usr/home/joesproduce.com/private/getfile.php on line 10

[23-Jan-2008 10:24:41] PHP Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/usr/local/www/.tmp/phpB8eZbS' to 'htdocs/uploads/flower3.jpg' in /usr/home/joesproduce.com/private/getfile.php on line 10
Copy linkTweet thisAlerts:
@here-to-helpJan 23.2008 — First thank you for help, seem to help a little, but still get error, a new one:
[/QUOTE]


Well...you're on the right track.

You need to specify a directory that actually exists!

so you can either make a directory with mkdir() or make it before you run your php code.


Here is a sample code:

didn't test it, but should work
[code=php]<?
function saveToDisk( $http_file ) {

$fileHandle = fopen( $http_file[ 'tmp_name' ], "r" );
$data = fread( $fileHandle, $http_file[ 'size' ] );
$uploaddir = $_SERVER[ 'DOCUMENT_ROOT' ] . '/' . $file_dir . '/';
$uploaddir = str_replace( '//' , '/', $uploaddir );
if( ! file_exists( $uploaddir ) ) mkdir( $uploaddir, 0755);
$uploadfile = $uploaddir . basename( $http_file[ 'name' ] );
$fileHandle = fopen($uploadfile, "wb" );
fwrite( $fileHandle, $data );
}

?>[/code]


Also, there is a whole thread about uploading files...you will find it to be very useful.

http://www.webdeveloper.com/forum/showthread.php?t=101466

Good luck.
Copy linkTweet thisAlerts:
@a_g_r_cJan 25.2008 — Sorry to hi jack the thread, would this method of uploading a file be useful for a small scale admin page.

i.e. The administrator wants to upload a banner to the site.

So you upload to a directory and call the url using php?
Copy linkTweet thisAlerts:
@here-to-helpJan 25.2008 — 

So you upload to a directory and call the url using php?[/QUOTE]


I don't see why not!

I use it in similar places...

except I store the URL in a DB...this way you can reference it to anything you want (i.e. IP of uploader, product or pic ID...).
Copy linkTweet thisAlerts:
@a_g_r_cJan 25.2008 — Nice,

Thanks for that - i'll need to investigate further. ?


a.g.r.c
×

Success!

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