473,386 Members | 1,699 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,386 software developers and data experts.

Undefined Index

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\karsazestate\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 3336
Markus
6,050 Expert 4TB
[php]
<?php
// ---------------------------------------------
// Pure PHP Upload version 1.1
// -------------------------------------------
if (phpversion() > "4.0.6") {
$_POST = &$_FILES;
}

define("MAX_SIZE",300000);
define("DESTINATION_FOLDER", "./myimages/");
define("no_error", "success.php");
define("yes_error", "error.php");
$_accepted_extensions_ = "jpg,jpeg,png,gif,bmp";
if(strlen($_accepted_extensions_) > 0){
$_accepted_extensions_ = @explode(",",$_accepted_extensions_);
} else {
$_accepted_extensions_ = array();
}

$myfile = $HTTP_POST_FILES['myimage'];

if(is_uploaded_file($myfile['tmp_name']) && $HTTP_POST_FILES['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($_ext_[count($_ext_)-1]);
if(!in_array($_ext_, $_accepted_extensions_) && count($_accepted_extensions_) > 0){
$errStr = "Estensione non valida";
}
if(!is_dir(DESTINATION_FOLDER) && is_writeable(DESTINATION_FOLDER)){
$errStr = "Cartella di destinazione non valida";
}
if(empty($errStr)){
if(@copy($_tmp_name_,DESTINATION_FOLDER . "/" . $_name_)){
header("Location: " . no_error);
} else {
header("Location: " . yes_error);
}
} else {
header("Location: " . yes_error);
}
}
?>
<form action="" method="post" enctype="multipart/form-data" name="form1" id="form1">
<table width="354" border="10" cellspacing="10" cellpadding="0">
<tr>
<td width="102">image</td>
<td width="252"><input 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 Expert 4TB
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 Expert 4TB
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
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: ...
9
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...
4
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: ...
9
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...
7
by: deepak | last post by:
Using 'char' as an array index is an undefined behavior?
3
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...
3
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:...
15
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...
5
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...
3
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...
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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,...
0
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...

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.