By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,002 Members | 2,137 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,002 IT Pros & Developers. It's quick & easy.

Re basic file upload form

P: n/a
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
Share this Question
Share on Google+
15 Replies


P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.