3 replies [Last post]
Scotty13
Scotty13's picture
Offline
Regular
Last seen: 8 years 6 weeks ago
Timezone: GMT-5
Joined: 2011-01-28
Posts: 14
Points: 25

In my web page I want members to be able to change there image/picture. Below are to sep. codes in edit_res.php

Error on line 83, it’s marked below.

_____________________________________________________

 
<form action="edit_res.php?id=<?php echo $id; ?>" method="post" enctype="multipart/form-data">
            <tr>
              <td width="61"><?php echo $user_pic; ?></td>
 
              <td width="521"><input name="fileField" type="file" class="formFields" id="fileField" size="42" />
 
              50 kb max </td>
              <td width="56"><input name="updateBtn1" type="submit" id="updateBtn1" value="Update" />
                <input name="parse_var" type="hidden" value="pic" />
                <input name="thisWipit" type="hidden" value="<?php echo $thisRandNum; ?>" />
              </td>
            </tr>
          </form>
        </table>

_________________________________________________________
 
	// ------- PARSING PICTURE UPLOAD ---------
if ($_POST['parse_var'] == "pic"){
 
	// If a file is posted with the form
	if ($_FILES['fileField']['tmp_name'] != "") { 
            $maxfilesize = 51200; // 51200 bytes equals 50kb
            if($_FILES['fileField']['size'] > $maxfilesize ) { 
 
                        $error_msg = '<font color="#FF0000">ERROR: Your image was too large, please try again.</font>';
                        unlink($_FILES['fileField']['tmp_name']); 
 
            } else if (!preg_match("/\.(gif|jpg|png)$/i", $_FILES['fileField']['name'] ) ) {
 
                        $error_msg = '<font color="#FF0000">ERROR: Your image was not one of the accepted formats, please try again.</font>';
                        unlink($_FILES['fileField']['tmp_name']); 
 
            } else { 
                         $newname = "image01.jpg";
       <strong>LINE 83</strong>:                 move_uploaded_file( $_FILES['fileField']['tmp_name'], "tktedmembers/$id/".$newname);
            }
    } 
}	

ERROR: When I try to test in browser.

Warning: move_uploaded_file(tktedmembers/33/image01.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/*******/edit_res.php on line 83

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/php1fgE1Z' to 'tktedmembers/33/image01.jpg' in /home/********/edit_res.php on line 83

Thanks,
Scotty13

Tags:
Tyssen
Tyssen's picture
Offline
Moderator
Brisbane
Last seen: 6 years 20 weeks ago
Brisbane
Timezone: GMT+10
Joined: 2004-05-01
Posts: 8201
Points: 1386

Check that the folder exists

And that it has correct permissions on it.

How to get help
Post a link. If you can't post a link, jsFiddle it.
My blog | My older articles | CSS Reference

Scotty13
Scotty13's picture
Offline
Regular
Last seen: 8 years 6 weeks ago
Timezone: GMT-5
Joined: 2011-01-28
Posts: 14
Points: 25

Permission folder and image

Permission folder and image set at 755.

Tyssen
Tyssen's picture
Offline
Moderator
Brisbane
Last seen: 6 years 20 weeks ago
Brisbane
Timezone: GMT+10
Joined: 2004-05-01
Posts: 8201
Points: 1386

File's not there

It's failing because it's trying to move a file that doesn't exist. Are you saving or renaming the uploaded file to the name of the file you're trying to move before doing the move_uploaded_file?

How to get help
Post a link. If you can't post a link, jsFiddle it.
My blog | My older articles | CSS Reference