Reputation: 1101
i want to retrieve image from client (ipod) programmed in objective c i use the following code
$TARGET_PATH = "pics/";
$image = $_FILES['photo'];
$TARGET_PATH =$TARGET_PATH . basename( $_FILES['photo']['name']);
$TARGET_PATH =$TARGET_PATH.".jpg";
if(file_exists($TARGET_PATH))
{
$TARGET_PATH =$TARGET_PATH .uniqid() . ".jpg";
}
if (move_uploaded_file($image['tmp_name'], $TARGET_PATH))
{
$TARGET_PATH="http://www.".$_SERVER["SERVER_NAME"]."/abc/".$TARGET_PATH;
echo $TARGET_PATH;
echo "image upload successfully";}
else{
echo "could not upload image";
}
this code upload five to six images successfully and after that it gives me error i.e
Notice: Undefined index: photo in /home/abc/public_html/abc.com/fish/mycatch_post.php on line 42
Notice: Undefined index: photo in /home/abc/public_html/abc.com/fish/mycatch_post.php on line 53
could not upload image
Upvotes: 0
Views: 151
Reputation: 4688
The error message seems to be telling you that there is no such element at key "photo" in the global $_FILES
array. That means the client didn't even send a file in the "photo" field.
As with any other input parameter, you should validate this condition before trying to access the element. For example, with: if (isset($_FILES['photo'])) {...}
. And even when $_FILES['photo']
is set, you should check $_FILES['photo']['error']
for exceptions such as partial uploads (UPLOAD_ERR_PARTIAL
) or empty uploads (UPLOAD_ERR_NO_FILE
) as described in the PHP Manual.
You can debug this problem by adding the proper validations, i.e., making sure that the file upload exists and has been successful.
Upvotes: 1