473,715 Members | 2,972 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

file upload not working right

after a file upload, $_FILES is not populated but $_POST is. what's going
on here?

$_POST[image][tmp_name]=C
$_POST[image][error]=C
$_POST[image][size]=C
$_POST[image]=C:\\www\\jimm\ \images\\bg1.jp g
$_FILES[image][tmp_name]=
$_FILES[image][error]=
$_FILES[image][size]=
$_FILES[image]=

Apr 19 '06 #1
4 5895
Jim Michaels wrote:
after a file upload, $_FILES is not populated but $_POST is. what's going
on here?

$_POST[image][tmp_name]=C
$_POST[image][error]=C
$_POST[image][size]=C
$_POST[image]=C:\\www\\jimm\ \images\\bg1.jp g
$_FILES[image][tmp_name]=
$_FILES[image][error]=
$_FILES[image][size]=
$_FILES[image]=


show us the form sourcecode. :-)

Regards,
Erwin
Apr 19 '06 #2
"Jim Michaels" <NO************ ***@yahoo.com> wrote in
news:QM******** ************@co mcast.com:
after a file upload, $_FILES is not populated but $_POST is. what's
going on here?


did you put the correct "enctype" in your form? (multipart/form-data)
Apr 19 '06 #3

"Good Man" <he***@letsgo.c om> wrote in message
news:Xn******** *************** *@216.196.97.13 1...
"Jim Michaels" <NO************ ***@yahoo.com> wrote in
news:QM******** ************@co mcast.com:
after a file upload, $_FILES is not populated but $_POST is. what's
going on here?


did you put the correct "enctype" in your form? (multipart/form-data)


that's what I was missing! (duh) boy, I haven't done this in a long time.
thanks!
Apr 19 '06 #4

"Erwin Moller"
<si************ *************** *************** @spamyourself.c om> wrote in
message news:44******** *************** @news.xs4all.nl ...
Jim Michaels wrote:
after a file upload, $_FILES is not populated but $_POST is. what's
going
on here?

$_POST[image][tmp_name]=C
$_POST[image][error]=C
$_POST[image][size]=C
$_POST[image]=C:\\www\\jimm\ \images\\bg1.jp g
$_FILES[image][tmp_name]=
$_FILES[image][error]=
$_FILES[image][size]=
$_FILES[image]=


show us the form sourcecode. :-)

Regards,
Erwin


It finally works.
this little function, bin2mysqlhex that I wrote, has saved my bacon on file
uploads to a BLOB type in a database. I can't seem to get anything else to
work. note that when you do an INSERT or UPDATE..SET, you don't use quotes
on the data.

function bin2mysqlhex($s ) {
$a='0x';
$q=array('0','1 ','2','3','4',' 5','6','7','8', '9','A','B','C' ,'D','E','F');
for($x=0; $x<strlen($s); $x++) {
$a .= $q[ord($s{$x})>>4]; //msb
$a .= $q[ord($s{$x})&0x0 f]; //lsb
}
return $a;
}

//images
if (isset($_POST['type']) && 'image'==$_POST['type'] &&
isset($_POST['action'])) switch($_POST['action']) {
case 'add':
if (!sqlinjections afe($_POST['mime_type'])
|| !sqlinjectionsa fe($_POST['comment'])
) {
exit;
}
if ('on'==strtolow er(ini_get("mag ic_quotes_gpc") ) ||
'1'==ini_get("m agic_quotes_gpc ")) {
if (isset($_SESSIO N['pc_id'])) {
//handle image upload
$escaped_conten ts='';
if (is_uploaded_fi le($_FILES['image']['tmp_name'])) {
// copy(str_replac e("\\","/",$_POST['img']),
// str_replace("\\ ","/",$_POST['img']['name']));
// $filename=str_r eplace("\\","/",$_POST['image']['tmp_name']);
$filename=str_r eplace("\\","/",$_FILES['image']['name']);
$filename=str_r eplace("//","/",$filename );
$fileext = strtolower(subs tr(strrchr($fil ename, "."), 1));
switch($fileext ) {
case "jpg": case "jpeg": case "jpe": default: $mimetype="imag e/jpeg";
break;
//case "tif": case "tiff": $mt="image/tiff"; break;
case "gif": $mimetype="imag e/gif"; break;
case "png": $mimetype="imag e/png"; break;
default: $mimetype=$_POS T['mime_type'];break; //unknown file ext. on
temp file.
}
if ($_FILES['image']['size']<150000) {
$contents = file_get_conten ts($_FILES['image']['tmp_name']);
unlink($_FILES['image']['tmp_name']);
$escaped_conten ts=bin2mysqlhex ($contents);
}
//$escaped_conten ts=$contents;
}
if ($_POST['image']['size']<150000) {
mysql_query("IN SERT INTO photos(image,mi me_type,comment )
VALUES($escaped _contents,'$mim etype','".nl2br (htmlentities($ _POST['answer']))."')",
$link);
$image_id=mysql _insert_id($lin k);
mysql_query("IN SERT INTO photos_photosca tegories(image_ id,pc_id)
VALUES($image_i d,$_SESSION[pc_id])", $link);
} else {
$contents='too large';
$escaped_conten ts='too large';
$image_id=0;
}
}
} else {
if (isset($_SESSIO N['pc_id'])) {
//handle image upload
$escaped_conten ts='';
if (is_uploaded_fi le($_FILES['image']['tmp_name'])) {
// copy(str_replac e("\\","/",$_POST['img']),
// str_replace("\\ ","/",$_POST['img']['name']));
// $filename=str_r eplace("\\","/",$_POST['image']['tmp_name']);
$filename=str_r eplace("\\","/",$_FILES['image']['name']);
$filename=str_r eplace("//","/",$filename );
$fileext = strtolower(subs tr(strrchr($fil ename, "."), 1));
switch($fileext ) {
case "jpg": case "jpeg": case "jpe": default: $mimetype="imag e/jpeg";
break;
//case "tif": case "tiff": $mt="image/tiff"; break;
case "gif": $mimetype="imag e/gif"; break;
case "png": $mimetype="imag e/png"; break;
default: $mimetype=$_POS T['mime_type'];break; //unknown file ext. on
temp file.
}
if ($_FILES['image']['size']<150000) {
$contents = file_get_conten ts($_FILES['image']['tmp_name']);
unlink($_FILES['image']['tmp_name']);
$escaped_conten ts=bin2mysqlhex ($contents);
}
}
if ($_POST['image']['size']<150000) {
mysql_query("IN SERT INTO photos(image,mi me_type,comment )
VALUES($escaped _contents,'$mim etype','".mysql _escape_string( nl2br(htmlentit ies($_POST['answer'])))."')",
$link);
$image_id=mysql _insert_id($lin k);
mysql_query("IN SERT INTO photos_photosca tegories(image_ id,pc_id)
VALUES($image_i d,$_SESSION[pc_id])", $link);
} else {
$contents='too large';
$escaped_conten ts='too large';
$image_id=0;
}
}
}
break;
case 'change':
if (!sqlinjections afe($_POST['mime_type'])
|| !sqlinjectionsa fe($_POST['comment'])
|| !sqlinjectionsa fe($_POST['pc_id'])
) {
exit;
}
if ('on'==strtolow er(ini_get("mag ic_quotes_gpc") ) ||
'1'==ini_get("m agic_quotes_gpc ")) {
//handle image upload
$escaped_conten ts='';
if (is_uploaded_fi le($_FILES['image']['tmp_name'])) {
// copy(str_replac e("\\","/",$_POST['img']),
// str_replace("\\ ","/",$_POST['img']['name']));
// $filename=str_r eplace("\\","/",$_POST['image']['tmp_name']);
$filename=str_r eplace("\\","/",$_FILES['image']['name']);
$filename=str_r eplace("//","/",$filename );
$fileext = strtolower(subs tr(strrchr($fil ename, "."), 1));
switch($fileext ) {
case "jpg": case "jpeg": case "jpe": default: $mimetype="imag e/jpeg";
break;
//case "tif": case "tiff": $mt="image/tiff"; break;
case "gif": $mimetype="imag e/gif"; break;
case "png": $mimetype="imag e/png"; break;
default: $mimetype=$_POS T['mime_type'];break; //unknown file ext. on temp
file.
}
if ($_FILES['image']['size']<150000) {
$contents = file_get_conten ts($_FILES['image']['tmp_name']);
unlink($_FILES['image']['tmp_name']);
$escaped_conten ts=bin2mysqlhex ($contents);
$image_id=intva l($_POST['image_id']);
echo "UPDATE";
mysql_query("UP DATE photos SET
comment='".nl2b r(htmlentities( $_POST['comment']))."',
image=$escaped_ contents,
mime_type='$mim etype'
WHERE image_id=".intv al($_POST['image_id'])
, $link) or die("UERR:".mys ql_error());
} else {
$contents='too large';
$escaped_conten ts='too large';
$image_id=0;
}
} else {
//no uploaded file. don't change what's already there.
mysql_query("UP DATE photos SET
comment='".nl2b r(htmlentities( $_POST['comment']))."',
mime_type='$mim etype',
WHERE image_id=".intv al($_POST['image_id']), $link) or
die("UERR:".mys ql_error());
}
} else {
//handle image upload
$escaped_conten ts='';
if (is_uploaded_fi le($_FILES['image']['tmp_name'])) {
// copy(str_replac e("\\","/",$_POST['img']),
// str_replace("\\ ","/",$_POST['img']['name']));
// $filename=str_r eplace("\\","/",$_POST['image']['tmp_name']);
$filename=str_r eplace("\\","/",$_FILES['image']['name']);
$filename=str_r eplace("//","/",$filename );
$fileext = strtolower(subs tr(strrchr($fil ename, "."), 1));
switch($fileext ) {
case "jpg": case "jpeg": case "jpe": default: $mimetype="imag e/jpeg";
break;
//case "tif": case "tiff": $mt="image/tiff"; break;
case "gif": $mimetype="imag e/gif"; break;
case "png": $mimetype="imag e/png"; break;
default: $mimetype=$_POS T['mime_type'];break; //unknown file ext. on temp
file.
}
if ($_FILES['image']['size']<150000) {
$contents = file_get_conten ts($_FILES['image']['tmp_name']);
unlink($_FILES['image']['tmp_name']);
$escaped_conten ts=bin2mysqlhex ($contents);
$image_id=intva l($_POST['image_id']);
mysql_query("UP DATE photos SET
comment='".mysq l_escape_string (nl2br(htmlenti ties($_POST['comment'])))."',
image=$escaped_ contents,
mime_type='$mim etype',
WHERE image_id=".intv al($_POST['image_id'])
, $link);
} else {
$contents='too large';
$escaped_conten ts='too large';
$image_id=0;
}
} else {
//no uploaded file. don't change what's already there.
mysql_query("UP DATE photos SET
comment='".mysq l_escape_string (nl2br(htmlenti ties($_POST['comment'])))."',
mime_type='$mim etype',
WHERE image_id=".intv al($_POST['image_id']), $link);
}
}
mysql_query("UP DATE quiz_batteries SET
title='".mysql_ escape_string(h tmlentities($_P OST['title']))."' WHERE
battery_id=".in tval($_POST['battery_id']), $link);
break;
case 'delete':
if (!sqlinjections afe($_POST['image_id'])) {
exit;
}
//delete from the relationship table first! foreign keys involved.
mysql_query("DE LETE FROM photos_photosca tegories WHERE
image_id=".intv al($_POST['image_id']), $link);
mysql_query("DE LETE FROM photos WHERE
image_id=".intv al($_POST['image_id']), $link);
break;
case 'select':
if (!sqlinjections afe($_POST['pc_id'])) {
exit;
}
$_SESSION['pc_id']=intval($_POST['pc_id']);
break;
}
<form action="editpho toalbum.php" method="post"
enctype="multip art/form-data">
<div class=addbox>
<div style="font-family:Verdana, Arial, Helvetica,
sans-serif;backgroun d-color:#CC9966;c olor:#000099;fo nt-size:large;font-weight:bold;tex t-align:center;"> Add
Image</div>
<br>
<label>Image File:
<input name="image" type="file"></label>(jpeg/gif/png)<br />
<label>Image Type: <select name="mime_type " size="1">
<option selected value="image/jpeg">JPEG</option>
<option value="image/png">PNG</option>
<option value="image/gif">GIF</option>
</select></label>(must match what you uploaded!<br>If the picture here
doesn't show, change the image type or re-upload.)<br />
<input name="action" type="hidden" value="add">
<input name="type" type="hidden" value="image">
<input name="" type="submit" value="Add">
</div>
</form>
<br style="clear:bo th;">
<br>
<?php
if (isset($_SESSIO N['pc_id'])) {
$q=mysql_query( "SELECT * FROM
photos INNER JOIN photos_photosca tegories
ON photos.image_id =photos_photosc ategories.image _id
WHERE photos_photosca tegories.pc_id= $_SESSION[pc_id]
ORDER BY photos.image_id ", $link) or die(mysql_error ());
while ($row=mysql_fet ch_assoc($q)) {
?>
<form action="editpho toalbum.php" method="post"
enctype="multip art/form-data">
<div class=editbox>
<div style="font-family:Verdana, Arial, Helvetica,
sans-serif;backgroun d-color:#CC9966;c olor:#000099;fo nt-size:large;font-weight:bold;tex t-align:center;"> Edit
Image</div>
<br>
<img src="viewtnimg. php?id=<?php echo $row['image_id']; ?>&width=150"
alt="image for answer" title="image for answer" width="150">Thu mbnail<br />
<label>Image File:
<input name="image" type="file"></label>(jpeg/gif/png)<br />
<label>Image Type: <select name="mime_type " size="1">
<option <?php if ($row['mime_type']=='image/jpeg'){echo
"selected=\"sel ected\"";} ?> value="image/jpeg">JPEG</option>
<option <?php if ($row['mime_type']=='image/png'){echo
"selected\"sele cted\"";} ?> value="image/png">PNG</option>
<option <?php if ($row['mime_type']=='image/gif'){echo
"selected=\"sel ected\"";} ?> value="image/gif">GIF</option>
</select></label>(must match what you uploaded!<br>
If the picture here doesn't show, change the image type or
re-upload.)<br />

<input name="image_id" type="hidden" value="<?php echo $row['image_id'];
?>">
<input name="type" type="hidden" value="image">
<select name="action" size="1">
<option selected value="change"> Change</option>
<option value="delete"> Delete</option>
</select>
<input name="" type="submit" value="Do It">
</div>
</form>
<br style="clear:bo th;">
<br>
<?php
}
mysql_free_resu lt($q);
}
?>
Apr 20 '06 #5

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

Similar topics

3
7096
by: Amy Kimber | last post by:
Hello, I have a file upload page, and I've had it working fine, it was beautiful :-) Anyway, the powers that be moved hosts... and it doesn't work now. The file name is correct, the directory where it's going on the server is correct (checked through prints etc.). I've changed the dir to 777 (is that right?) and this is what I get on the print_r($_FILES); line:
20
2507
by: CHIN | last post by:
Hi all.. here s my problem ( maybe some of you saw me on other groups, but i cant find the solution !! ) I have to upload a file to an external site, so, i made a .vbs file , that logins to the site, and then i have to select the file to upload.. i used sendkeys.. and i worked perfect.. BUT ... the computer must be locked for security ( obviusly ) reazons.. so..i think this probable solutions to unlock the computer and run the...
13
4312
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 that this is suppossed to end up as a component for others to use, and therefore I do NOT have access to their global.cs::Session_End() how do I cleanup files that were uploaded -- but obviously left stranded when the users aborted/gave up writting...
4
2794
by: Mark Miller | last post by:
I've been trying to execute a javascript function just before submit on a form that contains an <input type="file"> input field and it isn't working. The reason I want to do this is the end users will be uploading files that are between 1 and 2 Meg. in size, and they are not too knowledgeable about computers. I want to disable the form buttons so they can't hit them after they hit the "upload" button. We're trying to prevent them from...
1
4864
by: gryffin | last post by:
im trying to do file extension checking but its not working :( i have the following in the head <script language="JavaScript"> extArray = new Array(".jpg", ".png", ".bmp"); function LimitAttach(form, file) { allowSubmit = false; if (!file) return; while (file.indexOf("\\") != -1)
8
3488
by: mpar612 | last post by:
Hello, I am a newbie to PHP, MySQL. I am trying to create a basic file upload form. I want to get that working and then I want to integrate that into a form that will rename the file and save it to a directory and store the path to the file in the db, in addition to storing other text from other fields in the form. Then I will get that path using PHP to display the image file in a browser. First things first, I'm having difficulty...
4
6911
by: Vlad | last post by:
I am having problems using the file.create method within a function that is called when looping through an array of filepaths. If I call my function with a hardcoded file path --C:\Temp.txt the function creates the file as expected. When I loop through my array I get the error - "ArgumentException was unhandled - Illegal characters in path" The value "C:\Temp.txt" is the first value in the array - as it works
4
2935
cassbiz
by: cassbiz | last post by:
Could use some help here. This script is carrying over an image just fine but the text isn't coming over. can you see why it is not working???? from the form I want to carry over two lines of text and I can't find the error on why it isn't working. Any help is greatly appreciated. Here is the form
3
4430
by: premprakashbhati | last post by:
hi, good evening.. i am going to upload an image in a web form .....for that iam using HTML input(file) control and one web control button i.e., Upload_Button() here is the code ...its work fine when iam using a normal web page... but can't in content page.... Code in Master Page <%@ Master Language="C#" AutoEventWireup="true" CodeFile="submaster.master.cs" Inherits="submaster" %> <%@ Register Assembly="AjaxControlToolkit"...
1
2256
by: ririe | last post by:
Hi. I have a problem here. I want to upload a file together with its semester. So I create two field. One for the semester and one for the file to be uploaded. But the script doesn't work. I don't know why. However, if I try to upload the file without the semester field, the script is working. May be the problem comes from the semester field. This is my codes. Form.php ?><?php require_once('Connections/connection.php'); ?><?php if...
0
8718
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9340
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9196
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9103
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9047
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6646
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4738
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2539
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2118
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.