How to Upload Files to Apache2 Webserver

Writer MikeD254

Joined: 30 Jun 2020
Posts: 9
Location: USA, Melbourne


Post Posted: Tue 30 Jun 'twenty 15:32   Post subject: HTTP-POST FILE UPLOADS Reply with quote

I am trying to set upwards Apache2 on my Ubuntu server to take the ability to post client files to a directory on the server.
So far the �Choose File� function works.
In one case the client chooses a file on his machine the file proper noun appears side by side to the �Choose File button to ostend the client�s pick.
Once the file is chosen the client clicks on the �Upload Button�.
Here is my problem.
When the �Upload Push button� is pressed the server returns:
Not Found
The requested URL was not institute on this server.
The steps I have taken thus far is to:
ane. created a target path folder and given permissions to all users (chmod 777)
two. installed a post handler script
Code:

<?php

$target_path = "/dwelling/<username>/webbpost/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['proper noun']);

echo "Source=" .      $_FILES['uploadedfile']['proper name'] . "<br />";
echo "Destination=" .   $destination_path . "<br />";
echo "Target path=" .   $target_path . "<br />";
echo "Size=" .      $_FILES['uploadedfile']['size'] . "<br />";

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ".  basename( $_FILES['uploadedfile']['proper name']).
" has been uploaded";
} else{
repeat "There was an error uploading the file, please try again!";
}
?>


3. created the html class
Code:

<html>
<caput></caput>
<body>
<h4> File uploads </h4>
<form enctype="multipart/form-data" activity="/usr/lib/cgi-bin/upload.php"
method="mail service">
<p>
Select File:
<input type="file" size="35" name="uploadedfile" />
<input type="submit" proper name="Upload" value="Upload" />
</p>
</form>
</body>
</html>

Does anyone see what I accept washed incorrect so far ?
Is there some additional steps I need to accept ?
I am very grateful for any help or suggestions...

Last edited by MikeD254 on Wed 01 Jul 'xx 3:57; edited 1 time in full

Back to top James Blond
Moderator

Joined: xix January 2006
Posts: 7095
Location: Frg, Adjacent to Hamburg


Back to acme MikeD254

Joined: 30 Jun 2020
Posts: 9
Location: USA, Melbourne


Post Posted: Wed 01 Jul '20 four:05   Mail service field of study: Reply with quote

My mistake. I posted the incorrect version of the html form.
I have edited my post show the correct version with the path /usr/lib/cgi-bin/upload.php .

Thanks for taking time to await this over

Back to elevation James Blond
Moderator

Joined: 19 Jan 2006
Posts: 7095
Location: Germany, Next to Hamburg


Post Posted: Thu 02 Jul '20 9:06   Post field of study: Reply with quote

The php file should non be in the cgi-bin folder, merely in the same folder / document root as your html file is.
What also helps is in the top of the php file
Code:

<?php
error_reporting(E_ALL);
ini_set('display_errors','On');
Back to elevation MikeD254

Joined: thirty Jun 2020
Posts: 9
Location: USA, Melbourne


Post Posted: Thu 02 Jul 'xx 17:03   Mail subject: Reply with quote

Thanks.
Added the lawmaking yous suggested to the php file.
Moved the php file to document root folder.
Edited the html file to to reflect the path modify.
Restarted Apache2 server.

Still getting same result (The requested URL was not found on this server.), with no other error letters displayed.

I am stumped...?

Back to elevation James Blond
Moderator

Joined: 19 Jan 2006
Posts: 7095
Location: Germany, Next to Hamburg


Back to elevation MikeD254

Joined: 30 Jun 2020
Posts: 9
Location: USA, Melbourne


Post Posted: Fri 03 Jul '20 0:08   Postal service discipline: Reply with quote

Zip in the fault log well-nigh it.

Here is the admission log:

192.168.5.140 - - [02/Jul/2020:17:59:34 -0400] "GET /upld.html HTTP/1.1" 200 542 "http://userver/" "Mozilla/five.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.119 Safari/537.36"
192.168.five.140 - - [02/Jul/2020:17:59:43 -0400] "Mail /var/www/html/upload.php HTTP/i.one" 404 486 "http://userver/upld.html" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, similar Gecko) Chrome/83.0.4103.119 Safari/537.36"

Back to acme MikeD254

Joined: 30 Jun 2020
Posts: nine
Location: United states of america, Melbourne


Back to top mraddi

Joined: 27 Jun 2016
Posts: 136
Location: Sch�mberg, Baden-W�rttemberg, Germany


Post Posted: Fri 03 Jul 'twenty half-dozen:55   Post subject: Reply with quote

Hello MikeD254,

please apply "/upload.php" as class's "activity"-parameter (<grade method="post" activeness="/upload.php"...) and not the consummate physical path "/var/world wide web/html/upload.php".
The path yous encounter in Apache'southward admission.log is appended to the document-root, which is in your example "/var/world wide web/html" resulting in Apache trying to read the file "/var/world wide web/html/var/www/html/upload.php"...

Best regards
Matthias Smile

Back to tiptop MikeD254

Joined: 30 Jun 2020
Posts: 9
Location: USA, Melbourne


Post Posted: Fri 03 Jul '20 22:36   Mail service subject: Reply with quote

Success...!!
Now the file called uploads to the web server.
Simply left with one question.
After the file uploads the server displays this :

Source=ExtractPage2.jpg

Notice: Undefined variable: destination_path in /var/www/html/upload.php on line 9
Destination=
Target path=/home/mike/webbpost/ExtractPage2.jpg
Size=12047
The file ExtractPage2.jpg has been uploaded

Where tin I right the "undefined variable" on line 9?

Back to top mraddi

Joined: 27 Jun 2016
Posts: 136
Location: Sch�mberg, Baden-Due west�rttemberg, Germany


Post Posted: Sat 04 Jul '20 vi:fourteen   Post discipline: Reply with quote

Howdy,

the errormessage is correct equally the variable is not assigned a value before it is used on line 9 with
repeat "Destination=" . $destination_path . "<br />";

So you lot can either assign a value to $destination_path in the lines before or just delete line 9 Very Happy

Best regards
Matthias

Back to height MikeD254

Joined: 30 Jun 2020
Posts: ix
Location: USA, Melbourne


Post Posted: Sat 04 Jul 'twenty sixteen:07   Post subject: Reply with quote

Many thanks to James Bond, and Matthias for taking time to help. All is now working every bit information technology should, and I accept learned a lot. I more question, what is the difference between "Target_path" and "Destination_path" ?

Thanks once again for all your aid and guidance.

Mike

Dorsum to top mraddi

Joined: 27 Jun 2016
Posts: 136
Location: Sch�mberg, Baden-W�rttemberg, Deutschland


Post Posted: Sat 04 Jul '20 sixteen:24   Post subject: Reply with quote

Hullo Mike,

I don't know the deviation - from PHP's signal of view both are just variables.
$target_path is set by your code with "$target_path = ...".
$destination_path is never set up to a value and therefore reading its value results in the notice about undefined variable.

All-time regards
Matthias Very Happy

Dorsum to top MikeD254

Joined: 30 Jun 2020
Posts: 9
Location: USA, Melbourne


Post Posted: Sun 05 Jul '20 19:24   Post subject field: Reply with quote

Thanks once again...

Mike

Back to top

reuterdenerivery.blogspot.com

Source: https://www.apachelounge.com/viewtopic.php?t=8520

0 Response to "How to Upload Files to Apache2 Webserver"

Post a Comment

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel