472,983 Members | 2,211 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,983 software developers and data experts.

Re basic file upload form

I would like to create a very basic file upload add image form to add
to my web site and to keep them in a "tmp" directory within my web
hosting file manager once uploaded.
I understand the basic html for the form and the basic php scripting
but the fine details ie method post etc needs help also at this stage
I dont want to involve mysql data base. were should I start.
Jul 17 '05 #1
15 3132
Simon wrote:
I would like to create a very basic file upload add image form to add
to my web site and to keep them in a "tmp" directory within my web
hosting file manager once uploaded.
I understand the basic html for the form and the basic php scripting
but the fine details ie method post etc needs help also at this stage
I dont want to involve mysql data base. were should I start.


If you've not already done so, read

http://www.php.net/manual/en/features.file-upload.php

--
Jock
Jul 17 '05 #2
In article <5b**************************@posting.google.com >, Simon wrote:
I would like to create a very basic file upload add image form to add
to my web site and to keep them in a "tmp" directory within my web
hosting file manager once uploaded.
I understand the basic html for the form and the basic php scripting
but the fine details ie method post etc needs help also at this stage
I dont want to involve mysql data base. were should I start.


Start at the source. http://www.php.net/manual

--
http://home.mysth.be/~timvw
Jul 17 '05 #3
John Dunlop <us*********@john.dunlop.name> wrote in message news:<MP************************@News.Individual.N ET>...
Simon wrote:
I would like to create a very basic file upload add image form to add
to my web site and to keep them in a "tmp" directory within my web
hosting file manager once uploaded.
I understand the basic html for the form and the basic php scripting
but the fine details ie method post etc needs help also at this stage
I dont want to involve mysql data base. were should I start.


If you've not already done so, read

http://www.php.net/manual/en/features.file-upload.php


thanks for your reply .
I have read the online manual you recommend Its all there I have to
say the problem is I cant get any of the scripts to work Copy paste
the scripts to my files but nothing ,I have an error log that recieves
the errors so somthing is working parse errors on various lines but I
cant de bug the script I am hosting with yahoo who provide all the
configurations but no support for the actual programing. I will study
the pages you provided . But I feel there is somthing basic missing in
my attempts.
Jul 17 '05 #4
Simon wrote:

[About <http://www.php.net/manual/en/features.file-upload.php>:]
Copy paste the scripts to my files but nothing ,I have an error log
that recieves the errors so somthing is working parse errors on various
lines but I cant de bug the script


Whittle down a basic file upload script to a couple of lines. Then,
if problems persist, post it here.

--
Jock
Jul 17 '05 #5
John Dunlop <us*********@john.dunlop.name> wrote in message news:<MP************************@News.Individual.N ET>...
Simon wrote:

[About <http://www.php.net/manual/en/features.file-upload.php>:]
Copy paste the scripts to my files but nothing ,I have an error log
that recieves the errors so somthing is working parse errors on various
lines but I cant de bug the script


Whittle down a basic file upload script to a couple of lines. Then,
if problems persist, post it here.


will post a basic script that I am trying to use.
simon
Jul 17 '05 #6
John Dunlop <us*********@john.dunlop.name> wrote in message news:<MP************************@News.Individual.N ET>...
Simon wrote:

[About <http://www.php.net/manual/en/features.file-upload.php>:]
Copy paste the scripts to my files but nothing ,I have an error log
that recieves the errors so somthing is working parse errors on various
lines but I cant de bug the script


Whittle down a basic file upload script to a couple of lines. Then,
if problems persist, post it here.


This is the script I am trying to use for yahoo web hosting.
The first thing is does the html and php go on the same file as a .php
file or two seperate files.

------------------------------------------------------------------------
<body>
<form action="upload.php" method="post" ENCTYPE="multipart/form-data">
**Filename: <input type="text" size=40 name="filename"><br>
**<input type="file" size=40 name="file"><br>
**<input type="hidden" name="MAX_FILE_SIZE" value="1000000000">
**<input type="submit" value="**********************************Upload
*********************************">
</form>
<?php
if*($file*==*""*||*$file*==*"none")*{
**print*"You must specify a file to upload.<p><i>You need a
<b>/tmp</b> directory for uploads to work.</i><p>";
}
else*{
**$newfile*=*"/php/tmp/$filename";
**echo*"Uploaded*as:*$newfile<br>";
**//unlink($file);
}
?>
<hr>
</body>
Jul 17 '05 #7
Simon wrote:
The first thing is does the html and php go on the same file as a .php
file or two seperate files.
Up to you.

[ ... ]
**Filename: <input type="text" size=40 name="filename"><br>
What's this for? You've already got:
**<input type="file" size=40 name="file"><br>
which allows the user to select files.
**<input type="hidden" name="MAX_FILE_SIZE" value="1000000000">
Mostly useless.
**<input type="submit" value="**********************************Upload
*********************************">
Browsers might ignore that leading and trailing whitespace. Got a
good reason for including it? If not, remove it.
</form>
<?php
if*($file*==*""*||*$file*==*"none")*{


You didn't copy 'n paste this from the Manual, did you?

http://www.php.net/manual/en/features.file-upload.php

--
Jock
Jul 17 '05 #8
John Dunlop <us*********@john.dunlop.name> wrote in message news:<MP************************@News.Individual.N ET>...
Simon wrote:
The first thing is does the html and php go on the same file as a .php
file or two seperate files.


Up to you.

[ ... ]
**Filename: <input type="text" size=40 name="filename"><br>


What's this for? You've already got:
**<input type="file" size=40 name="file"><br>


which allows the user to select files.
**<input type="hidden" name="MAX_FILE_SIZE" value="1000000000">


Mostly useless.
**<input type="submit" value="**********************************Upload
*********************************">


Browsers might ignore that leading and trailing whitespace. Got a
good reason for including it? If not, remove it.
</form>
<?php
if*($file*==*""*||*$file*==*"none")*{


You didn't copy 'n paste this from the Manual, did you?

http://www.php.net/manual/en/features.file-upload.php

Hi Jock

im sorry about that I posted the wrong script. I hope you dont mind
helping with this Ill post the sript from the manual .
<form enctype="multipart/form-data" action="_URL_" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
Send this file: <input name="userfile" type="file" />
<input type="submit" value="Send File" />
</form>

<?php
// In PHP versions earlier than 4.1.0, $HTTP_POST_FILES should be used
instead
// of $_FILES.

$uploaddir = '/var/www/uploads/';
$uploadfile = $uploaddir . $_FILES['userfile']['name'];

print "<pre>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile))
{
** print "File is valid, and was successfully uploaded. ";
** print "Here's some more debugging info:\n";
** print_r($_FILES);
} else {
** print "Possible file upload attack!* Here's some debugging
info:\n";
** print_r($_FILES);
}
print "</pre>";

?>
This is the script and form we can work on if you dont mind
I have tried this however nothing appears to find its way to my tmp
directory. can we wittle this down to the bare script.

1 I have checked file uploads are allowed and enabled
2 php is installed on my server yahoo web hosting
3 the html form appears and works a file is selected from the local
disc.
4 press upload and thats it .
5 nothing appears in my tmp directory.

could you script this so it is on one php file only.

Regards
Simon
Jul 17 '05 #9
Simon wrote:

[ ... ]
1 I have checked file uploads are allowed and enabled
2 php is installed on my server yahoo web hosting
3 the html form appears and works a file is selected from the local
disc.
4 press upload and thats it .
5 nothing appears in my tmp directory.


Stick "error_reporting(E_ALL);" at the start of your script.

--
Jock
Jul 17 '05 #10
John Dunlop <us*********@john.dunlop.name> wrote in message news:<MP************************@News.Individual.N ET>...
Simon wrote:

[ ... ]
1 I have checked file uploads are allowed and enabled
2 php is installed on my server yahoo web hosting
3 the html form appears and works a file is selected from the local
disc.
4 press upload and thats it .
5 nothing appears in my tmp directory.


Stick "error_reporting(E_ALL);" at the start of your script.


Have put on start of script.

log reports
parse error line 22
print "File is valid, and was successfully uploaded. ";

I have taken the form and script exactly as it is in the manual are
there details that I should change to make it work for my web hosting
example
should I add my domain and user id passwords etc somewhere.

regards
simon
Jul 17 '05 #11
John Dunlop <us*********@john.dunlop.name> wrote in message news:<MP************************@News.Individual.N ET>...
Simon wrote:

[ ... ]
1 I have checked file uploads are allowed and enabled
2 php is installed on my server yahoo web hosting
3 the html form appears and works a file is selected from the local
disc.
4 press upload and thats it .
5 nothing appears in my tmp directory.


Stick "error_reporting(E_ALL);" at the start of your script.

More error reports.
[19-Apr-2004 09:01:34] PHP Warning: File Upload Error - No Mime
boundary found after start of file header in Unknown on line 0
[19-Apr-2004 09:01:34] PHP Parse error: parse error in /test.php on
line 23
Jul 17 '05 #12
John Dunlop <us*********@john.dunlop.name> wrote in message news:<MP************************@News.Individual.N ET>...
Simon wrote:

[ ... ]
1 I have checked file uploads are allowed and enabled
2 php is installed on my server yahoo web hosting
3 the html form appears and works a file is selected from the local
disc.
4 press upload and thats it .
5 nothing appears in my tmp directory.


Stick "error_reporting(E_ALL);" at the start of your script.


[19-Apr-2004 09:05:59] PHP Warning: Max file size exceeded - file
[userfile] not saved in Unknown on line 0
[19-Apr-2004 09:05:59] PHP Parse error: parse error in /test.php on
line 23
Jul 17 '05 #13
Simon wrote:

[Concerning the second example from "PHP: Handling file uploads -
Manual", <http://www.php.net/manual/en/features.file-upload.php>:]
parse error line 22
print "File is valid, and was successfully uploaded. ";

I have taken the form and script exactly as it is in the manual


Therein lies the problem. The fault is entirely the Manual's; its
inconsistent, and sometimes ignorant and clueless, style of presenting
examples caused this. I stress this is *not* your fault.

If you look closely, you'll find the first two characters of line
twenty-two aren't normal spaces but, probably, no-break spaces, which
are the cause of the parse error (at least they are in my version of
PHP). Viewing the source, one finds the offending line:

&nbsp;&nbsp; print [ ... ]

Two solutions: either substitute normal spaces for those no-break
spaces or simply remove them. Hopefully you'll straighten out the
other errors (actually, warnings) you enumerated in this thread.

--
Jock
Jul 17 '05 #14
de**********@yahoo.com (Simon) wrote in message news:<5b**************************@posting.google. com>...
John Dunlop <us*********@john.dunlop.name> wrote in message news:<MP************************@News.Individual.N ET>...
Simon wrote:

[ ... ]
1 I have checked file uploads are allowed and enabled
2 php is installed on my server yahoo web hosting
3 the html form appears and works a file is selected from the local
disc.
4 press upload and thats it .
5 nothing appears in my tmp directory.


Stick "error_reporting(E_ALL);" at the start of your script.


[19-Apr-2004 09:05:59] PHP Warning: Max file size exceeded - file
[userfile] not saved in Unknown on line 0
[19-Apr-2004 09:05:59] PHP Parse error: parse error in /test.php on
line 23


John

Success I have found a upload form that works although it requires
some work but the basics are there wich is what I am looking for. Ill
post it in a day or so for you to see. and maybe we can take it from
there.

many thanks for your help.
simon
Jul 17 '05 #15
John Dunlop <us*********@john.dunlop.name> wrote in message news:<MP************************@News.Individual.N ET>...
Simon wrote:

[Concerning the second example from "PHP: Handling file uploads -
Manual", <http://www.php.net/manual/en/features.file-upload.php>:]
parse error line 22
print "File is valid, and was successfully uploaded. ";

I have taken the form and script exactly as it is in the manual


Therein lies the problem. The fault is entirely the Manual's; its
inconsistent, and sometimes ignorant and clueless, style of presenting
examples caused this. I stress this is *not* your fault.

If you look closely, you'll find the first two characters of line
twenty-two aren't normal spaces but, probably, no-break spaces, which
are the cause of the parse error (at least they are in my version of
PHP). Viewing the source, one finds the offending line:

&nbsp;&nbsp; print [ ... ]

Two solutions: either substitute normal spaces for those no-break
spaces or simply remove them. Hopefully you'll straighten out the
other errors (actually, warnings) you enumerated in this thread.


John

I now have the form as my index.php which works fine.

<?php
echo "<title>File Upload</title>";
echo "<h1 align=\"center\">File Upload</h1>";
echo "<div align=\"center\"><b></b><br>";
echo "<b></b><br>";
echo "<b></b></div><br>";
echo "<div align=\"center\">";
echo "<style type=\"text/css\">
BODY{font-family:Verdana, Arial, Helvetica, sans-serif}
</style><form method=post action=\"tmp/upload.php\"
enctype=\"multipart/form-data\">
<p><strong>File to Upload :</strong><br><input type=file name=img1
size=30></p>
<p><input type=submit value=\"Upload File\"></p></form>";
?>

The echo statements at the top are for my own text .

The upload.php script on second file is .

<?php

$webServer="";

echo "<title>File Upload</title>";
echo "<h1 align=\"center\">File Upload</h1>";
echo "<div align=\"center\"><b></b><br>";
echo "<b></b><br>";
echo "<b></b></div><br>";
echo "<div align=\"center\">";
echo "<style type=\"text/css\">
BODY{font-family:Verdana, Arial, Helvetica, sans-serif}
</style>";

# Check whether file is uploaded successfully
if($img1_name!=""){
@copy("$img1","$webServer$img1_name") or die("Couldn't copy the
file");
}
else{
die("No input file specified!$img1_name");
}
echo "<html><head><title>Successful File
Upload</title></head><body><h2>Success!</h2>
<p>You sent : $img1_name, a $img1_size byte file with a mime type of
$img1_type.</p>
<a href=\"/index.php\">Upload another file</a></body></html>";
?>

I dont no why this combination works I will break it down over the
next week or so.

My next task would be to would be to use this script and try to extend
it to upload say five files at one time. any ideas.

regards
Simon
Jul 17 '05 #16

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
13
by: Sky Sigal | last post by:
I have created an IHttpHandler that waits for uploads as attachments for a webmail interface, and saves it to a directory that is defined in config.xml. My question is the following: assuming...
2
by: mark | last post by:
How do I detect that a particular form element is a file upload or if the file upload has worked? In the Python cgi module documentation I found suggested code... form = cgi.FieldStorage()...
7
by: pbd22 | last post by:
hi. i am having probs understanding how to grab a file being uploaded from a remote client. i am using hidden input fields for upload such as: <input id="my_file_element" type="file"...
3
by: MarkusJNZ | last post by:
Hi, does anyone know of a good (Preferably free but don't mind paying some $$ for source code) basic document sharing application? Basically, a single admin should be able to upload files to a...
1
by: pbd22 | last post by:
hi. i have been posting this here and elsewhere a lot and can't seem to get resolution on this problem. i have been trying to upload files using a hidden iframe to a asp.net/vb.net form. the...
2
by: hotflash | last post by:
Hi All, I found the best pure ASP code to upload a file to either server and/or MS Access Database. It works fine for me however, there is one thing that I don't like and have tried to fix but...
1
by: chrisj | last post by:
I'm using freeASPupload and got some assistance integrating to a Member script. It works successfully. In this modified version there are two groups that use this upload script. Members of one...
6
Jacotheron
by: Jacotheron | last post by:
I need a PHP script that can upload music files (mp3). The script is for a home project I have started a while ago. I have a MySQL database of all the music that I have. Other computers on the...
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
3
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be using a very simple database which has Form (clsForm) & Report (clsReport) classes that simply handle making the calling Form invisible until the Form, or all...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
NeoPa
by: NeoPa | last post by:
Introduction For this article I'll be focusing on the Report (clsReport) class. This simply handles making the calling Form invisible until all of the Reports opened by it have been closed, when it...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.