473,387 Members | 1,541 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

Form Post Issues

I have a webpage that uploads a photo picture file to server, but goes
through some error checking before it redirects to the next page. Since I do
not have PHP compiled with mime type support I have checking last 3
characters of filename. Here are my problems:

1) When I set form type to ENCTYPE="multipart/form-data" i can check the
file size correctly and works fine, but then filename and extension are in
some weird format which is binary I believe.

form = 1
Photo: /tmp/phpnDF01W
image_x = 89
image_y = 16
Ext: 01w < this is wrong, should be gif/jpg/etc...
Size: 34326
File: /tmp/phpnDF01W < this is wrong

2) When I omit the above form type and use default, file size function fails
but the extension and filename work correctly. I believe this is because it
is sent in ascii/plain text mode.

Warning: filesize(): Stat failed for C:\\WINDOWS\\Desktop\\sci.psd
(errno=2 - No such file or directory) in
/home/fcl/public_html/free/index3.php on line 30

form = 1
photo = C:\\WINDOWS\\Desktop\\sci.psd
image_x = 66
image_y = 12
Ext: psd
Size: ??????
File = C:\\WINDOWS\\Desktop\\sci.psd

3) I'm also trying to get the file to the server and it's not uploading it.
It's creating the directories but not moving the file up there for me!!
4) Here is code. What is going on? Can I kill 3 birds with one stone here???
I'd rather not recompile PHP. Must I convert $ext from binary to plain
text??

while(list($key, $value) = each($HTTP_GET_VARS)) {

echo "$key = $value<br>";
}
if ($form) {

if ($photo) {

$ext = strtolower(substr($photo, -3));

function fsize($photo) {
return filesize($photo);
}

$size = fsize($photo);

if ($size > 100000) {

$focus = "photo";
$msg = "Your file size exceeds the maximum allowed
upload. Please re-submit or skip this step.";

} elseif (!preg_match("/(gif|peg|jpg|bmp|png)$/",
$ext)) {

$focus = "photo";
$msg = "Invalid file type. Please submit a gif, jpeg,
bmp, or png photo.";

} else {

if ($ltype == "1") { $type = "hotel"; }<-- this all works fine, etc
if ($ltype == "2") { $type = "inn"; }
if ($ltype == "3") { $type = "bandb"; }
if ($ltype == "4") { $type = "resort"; }

$imgdir = "$DOCUMENT_ROOT/lodging/$type"; <-- this all works fine,etc
if (!file_exists($imgdir)) { mkdir($imgdir, 0755); }
$imgdir.= "/$aid";
if (!file_exists($imgdir)) { mkdir($imgdir, 0755); }

move_uploaded_file($photo, "$imgdir/photo1.jpg"); <---this is not
working!!

loc("index4.php?sid=$sid&aid=$aid"); <-- works fine

}}
<form name="form1" method="post"
action="<?=$SCRIPT_NAME?>?sid=<?=$sid?>&aid=<?=$ai d?>&ltype=<?=$ltype?>"
ENCTYPE="multipart/form data">
<input type="hidden" name="form" value="1">

Jul 17 '05 #1
2 2279
pd*****@comcast.net says...
I have a webpage that uploads a photo picture file to server, but goes
through some error checking before it redirects to the next page. Since I do
not have PHP compiled with mime type support I have checking last 3
characters of filename. Here are my problems:

1) When I set form type to ENCTYPE="multipart/form-data" i can check the
file size correctly and works fine, but then filename and extension are in
some weird format which is binary I believe.

form = 1
Photo: /tmp/phpnDF01W
image_x = 89
image_y = 16
Ext: 01w < this is wrong, should be gif/jpg/etc...
Size: 34326
File: /tmp/phpnDF01W < this is wrong
No, it's not wrong. It's just the unique temporary name PHP gives to
the temporary copy of the file. The file name attribute is
independently available to you, just not there. Try this:

<?php
if (!isset($infile)) {
echo '
<form action="'.$PHP_SELF.'" ENCTYPE="multipart/form-data"
method=post>
<input type=file name=infile><br>
<input type=submit>
</form>
';
} else {
echo '
File Name:'.$infile_name.' is '.$infile_size.' bytes in size.
';
}
?>

Note the name of the file ($infile) in the form and the use of the
system-generated variables $infile_name and $infile_size.

Not that I'd ever use that approach. For starters, I'd want to rename
the file to a unique value, something like a database record number.
} elseif (!preg_match("/(gif|peg|jpg|bmp|png)$/",$ext)) {


And I'd never trust end-user input to be that correct. Mac users among
others aren't likely to bother with file name extensions at all.

Use the in-built image functions to get the definitive image type.

$imagestats=getImageSize($infile);

if ($imagestats[2]=1) {
copy ($infile, "images/user1.gif");
} elseif ($imagestats[2]=2) {
copy ($infile, "images/user1.jpg");
} elseif ($imagestats[2]=3) {
copy ($infile, "images/user1.png");
} elseif ($imagestats[2]=6) {
copy ($infile, "images/user1.bmp");
} elseif ($imagestats[2]=7) {
copy ($infile, "images/user1.tiff");
} elseif ($imagestats[2]=9) {
copy ($infile, "images/user1.tiff");
} else {
echo '
Sorry user1, supplied file is not a supported image type!
';
}

Cheers,

Geoff M
Jul 17 '05 #2
Thank you. This works like a charm!

$imagestats=getImageSize($photo);

$imgdir = "$DOCUMENT_ROOT/lodging/$type";
if (!file_exists($imgdir)) { mkdir($imgdir, 0755); }
$imgdir.= "/$aid";
if (!file_exists($imgdir)) { mkdir($imgdir, 0755); }

if ($photo_size > 100000) {

$focus = "photo";
$msg = "Your file size exceeds the maximum allowed upload of
100k.<br>Please re-submit or skip this step.";

} elseif (!preg_match("/(1|2|3|6|7|8)$/", $imagestats[2])) {

$focus = "photo";
$msg = "Invalid file type. Please submit a gif, jpeg, bmp, png, or tiff
photo. Or skip this step.";

} else { etc..

Jul 17 '05 #3

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

Similar topics

2
by: Steve | last post by:
I'm working in PHP, but am also using JavaScript, so perhaps there is a better way to do this using more PHP code...... I setup a search screen for my database, the user enters data and submits...
2
by: Marco | last post by:
Hi, Suppose you want to make sure subitted data is comming from "your" form and not submitted (with tools) elsewhere. What do I need to prevent false/hacked/spoofed data? - register globals ...
0
by: Bharat Suneja | last post by:
Hi All, I'm running into issues with passing the distinguishedName of a user as a hidden form field in a form from one page to the result page. Page 1: User enters user name in a form field ...
13
by: Ian.Suttle | last post by:
I am have been researching this issue to no end, so any help would be very much appreciated. I have a page with form tags. Inside of the form tags is a panel that contains a user control. The...
6
by: drec | last post by:
I am just learning Javascript and I would like to create a basic form that gives me two options. This will be using either checkbox or radio input type, however I would like the second option to...
3
by: steve | last post by:
Hi All I have a VB.net 2005 App which has a form set as the Application splash screen in Project properties Another form is set as the startup form All works great until the splash screen...
4
by: ms | last post by:
Something weird is going on here, an HttpHandler works perfectly, exect when I post a form to it using the post method it gives me an file not found 404 error, if I post to it using the get method...
26
by: Jerim79 | last post by:
I need to create a form that takes a number that the user enters, and duplicates a question the number of times the user entered. For instance, if the customer enters 5 on the first page, when...
2
by: Robertjb1 | last post by:
First Post - New member - I've searched the discussions available to no avail. I have, however, learned a few things in doing so. (Great Site -- Thanks) My issue is as follows: Access 2003/WinXP...
6
by: Aussie Rules | last post by:
Hi, I have an asp.net 2.0 page that has two sections. Each section allows the user to enter a value into a text box, click a button and then perform some function. Each text boxes function is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

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.