473,799 Members | 3,158 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Undefined Index

1 New Member
I just download dreamweaver extension for image upload. and run, It have some error... can anybody help... pls.. i have php 4.3.10. Notice: Undefined index: myimage in c:\program files\easyphp1-8\www\karsazest ate\upload.php on line 20
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. //    ---------------------------------------------
  3. //    Pure PHP Upload version 1.1
  4. //    -------------------------------------------
  5. if (phpversion() > "4.0.6") {
  6.     $_POST = &$_FILES;
  7. }
  8.  
  9. define("MAX_SIZE",300000);
  10. define("DESTINATION_FOLDER", "./myimages/");
  11. define("no_error", "success.php");
  12. define("yes_error", "error.php");
  13. $_accepted_extensions_ = "jpg,jpeg,png,gif,bmp";
  14. if(strlen($_accepted_extensions_) > 0){
  15.     $_accepted_extensions_ = @explode(",",$_accepted_extensions_);
  16. } else {
  17.     $_accepted_extensions_ = array();
  18. }
  19.  
  20. $myfile = $HTTP_POST_FILES['myimage'];
  21.  
  22. if(is_uploaded_file($myfile['tmp_name']) && $HTTP_POST_FILES['myimage']['error'] == 0){
  23.     $errStr = "";
  24.     $_name_ = $myfile['name'];
  25.     $_type_ = $myfile['type'];
  26.     $_tmp_name_ = $myfile['tmp_name'];
  27.     $_size_ = $myfile['size'];
  28.     if($_size_ > MAX_SIZE && MAX_SIZE > 0){
  29.         $errStr = "File troppo pesante";
  30.     }
  31.     $_ext_ = explode(".", $_name_);
  32.     $_ext_ = strtolower($_ext_[count($_ext_)-1]);
  33.     if(!in_array($_ext_, $_accepted_extensions_) && count($_accepted_extensions_) > 0){
  34.         $errStr = "Estensione non valida";
  35.     }
  36.     if(!is_dir(DESTINATION_FOLDER) && is_writeable(DESTINATION_FOLDER)){
  37.         $errStr = "Cartella di destinazione non valida";
  38.     }
  39.     if(empty($errStr)){
  40.         if(@copy($_tmp_name_,DESTINATION_FOLDER . "/" . $_name_)){
  41.             header("Location: " . no_error);
  42.         } else {
  43.             header("Location: " . yes_error);
  44.         }
  45.     } else {
  46.         header("Location: " . yes_error);
  47.     }
  48. }
  49. ?>
  50. <form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
  51. <table width="354" border="10" cellspacing="10" cellpadding="0">
  52.   <tr>
  53.     <td width="102">image</td>
  54.     <td width="252"><input type="file" name="myimage" /></td>
  55.   </tr>
  56.   <tr>
  57.     <td>&nbsp;</td>
  58.     <td><input type="submit" name="Submit" value="Submit" /></td>
  59.   </tr>
  60. </table>
  61. </form>
Please enclose any code within the proper code tags. See the Posting Guidelines on how to do that. - moderator
Mar 8 '08 #1
3 3359
Markus
6,050 Recognized Expert Expert
[php]
<?php
// ---------------------------------------------
// Pure PHP Upload version 1.1
// -------------------------------------------
if (phpversion() > "4.0.6") {
$_POST = &$_FILES;
}

define("MAX_SIZ E",300000);
define("DESTINA TION_FOLDER", "./myimages/");
define("no_erro r", "success.ph p");
define("yes_err or", "error.php" );
$_accepted_exte nsions_ = "jpg,jpeg,png,g if,bmp";
if(strlen($_acc epted_extension s_) > 0){
$_accepted_exte nsions_ = @explode(",",$_ accepted_extens ions_);
} else {
$_accepted_exte nsions_ = array();
}

$myfile = $HTTP_POST_FILE S['myimage'];

if(is_uploaded_ file($myfile['tmp_name']) && $HTTP_POST_FILE S['myimage']['error'] == 0){
$errStr = "";
$_name_ = $myfile['name'];
$_type_ = $myfile['type'];
$_tmp_name_ = $myfile['tmp_name'];
$_size_ = $myfile['size'];
if($_size_ > MAX_SIZE && MAX_SIZE > 0){
$errStr = "File troppo pesante";
}
$_ext_ = explode(".", $_name_);
$_ext_ = strtolower($_ex t_[count($_ext_)-1]);
if(!in_array($_ ext_, $_accepted_exte nsions_) && count($_accepte d_extensions_) > 0){
$errStr = "Estensione non valida";
}
if(!is_dir(DEST INATION_FOLDER) && is_writeable(DE STINATION_FOLDE R)){
$errStr = "Cartella di destinazione non valida";
}
if(empty($errSt r)){
if(@copy($_tmp_ name_,DESTINATI ON_FOLDER . "/" . $_name_)){
header("Locatio n: " . no_error);
} else {
header("Locatio n: " . yes_error);
}
} else {
header("Locatio n: " . yes_error);
}
}
?>
<form action="" method="post" enctype="multip art/form-data" name="form1" id="form1">
<table width="354" border="10" cellspacing="10 " cellpadding="0" >
<tr>
<td width="102">ima ge</td>
<td width="252"><in put type="file" name="myimage" /></td>
</tr>
<tr>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit" /></td>
</tr>
</table>

</form>
[/php]
It makes it so much easier for people to read. (please read forum guidelines)
Mar 8 '08 #2
Markus
6,050 Recognized Expert Expert
When you get "undefined index" it means that you have referred to an indeces in an array which doesnt exist. i.e. 'myimage' in http_post_files () doesnt exist.

In my oppinion, that code is awful and old. old. old. old.
check out this tutorial. It's much neater and well up-to-date :)
Mar 8 '08 #3
ronverdonk
4,258 Recognized Expert Specialist
Of course the myimage key does not exist because you haven't submitted the upload form when you first enter the script.

Ronald
Mar 8 '08 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

7
2815
by: Coder Droid | last post by:
I decided to run some code with errors set to E_ALL, just to see what I would run across. It caught a few things, but 90% or better of the messages were of the 'undefined' kind: PHP Notice: Undefined variable PHP Notice: Undefined index PHP Notice: Undefined property I'd like to go back and fix what I can, but I'm wondering: how good or bad is this? I mean, I rely on the fact that the first use of a variable
9
9605
by: petermichaux | last post by:
Hi, I am curious about how php deals with the following situation where I use an undefined index into an array. PHP seems to be behaving exactly how I want it to but I want to make sure that it is not a fluke. It seems like most programming languages would crash if you used an undefined index. Why does PHP work the way it does? My example is below
4
7196
by: John Oliver | last post by:
PHP Notice: Undefined index: name in /home/www/reformcagunlaws.com/new.php on line 6 PHP Notice: Undefined index: address in /home/www/reformcagunlaws.com/new.php on line 7 PHP Notice: Undefined index: city in /home/www/reformcagunlaws.com/new.php on line 8 PHP Notice: Undefined index: county in /home/www/reformcagunlaws.com/new.php on line 9 PHP Notice: Undefined index: zip in /home/www/reformcagunlaws.com/new.php on line...
9
1871
by: Alan Schroeder | last post by:
The following code produces the expected results on a PC using gcc, but I need to port it (or least something similar) to a different platform/compiler. I don't think I've introduced any undefined behavior but would like another set of eyes to check. #include <math.h> #include <stdlib.h> extern float window;
7
2216
by: deepak | last post by:
Using 'char' as an array index is an undefined behavior?
3
4967
cassbiz
by: cassbiz | last post by:
Here are the errors that are coming up in my error_log Notice: Undefined index: andatum in /zipcode.php on line 11 Notice: Undefined index: andatum in /zipcode.php on line 12 Notice: Undefined index: abdatum in /zipcode.php on line 13 Notice: Undefined index: zimmer in /zipcode.php on line 14 Notice: Undefined index: city in /zipcode.php on line 39 Notice: Undefined index: state in /zipcode.php on line 41
3
5505
by: number1yan | last post by:
Can anyone help me, i am creating a website and am using a php script that recomends the website to other people. I keep getting the same error and can not work out why. The error is: Notice: Undefined index: FriendName in D:\Yan\Over_8\SendEmail.php on line 4, Notice: Undefined index: FriendEmail in D:\Yan\Over_8\SendEmail.php on line 5, Notice: Undefined index: Name in D:\Yan\Over_8\SendEmail.php on line 6, Notice: Undefined index: Email...
15
4486
by: bill | last post by:
I am trying to write clean code but keep having trouble deciding when to quote an array index and when not to. sometimes when I quote an array index inside of double quotes I get an error about enased whitespace (to my best memory) AT other times I get an undefined index notice as below: Notice: Undefined index: last_reminder_id in...
5
7194
by: siyaverma | last post by:
Hi, I am new to php, i was doing some small chnages in a project developed by my collegue who left the job and i got the responsibility for that, After doing some changes when i run it on my local server it was working fine but giving some errors those are Notice: Undefined index: phplogin in C:\Inetpub\wwwroot\sampleft\index.php on line 116 Notice: Undefined variable: username in C:\Inetpub\wwwroot\sampleft\index.php on line 116 ...
3
3878
by: sickboy | last post by:
$channels=$_GET; if (empty($channels)) { $channels='blank'; } changechannels($channels); $theatre=$_GET; if (empty($theatre)) { $theatre='splash'; } changetheatre($theatre); $info=$_GET; if (empty($info)) { $info='noinfo'; } changeinfo($info); Hey everyone, I keep getting an error regarding the above code. These are the errors: Notice: Undefined index: channels in /home/forcefed/public_html/index.php on line 5
0
9685
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9538
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,...
1
10214
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
9067
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7561
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
5583
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4135
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3751
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2935
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.