Image Upload Question

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
anishgiri
Forum Newbie
Posts: 7
Joined: Mon May 31, 2010 12:49 am

Image Upload Question

Post by anishgiri »

I tried this script that I found on the web, it upload the files, but it shows notices. Below are the notices. How can I fix these?

Notice: Undefined index: completed in C:\wamp\www\image upload2\image_upload.php on line 2
Notice: Undefined index: completed in C:\wamp\www\image upload2\image_upload.php on line 10
Please upload an image

Here is the code

Code: Select all

<?php
if ($_REQUEST['completed'] == 1) {
$newname = uniqid("whc").".jpg";
move_uploaded_file($_FILES['mailfile']['tmp_name'],
"robdemo/$newname");
} ?>
<html>
<head><title>Upload page</title></head>
<body><h1>Image Uploader</h1>
<?php if ($_REQUEST['completed'] != 1) { ?>
<b>Please upload an image</b><br>
<form enctype=multipart/form-data method=post>
<input type=hidden name=MAX_FILE_SIZE value=1500000>
<input type=hidden name= 'completed' value=1>
Choose file to send: <input type=file name=mailfile> and
<input type=submit></form>
<?php } else { ?>
<b>Yum, Yum. I enjoyed that</b>
<?php } ?>
<hr>
Copyright, etc
</body></html>
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Image Upload Question

Post by requinix »

You need to check that array indexes exist before trying to use them.
Post Reply