homepage Welcome to WebmasterWorld Guest from 54.227.25.58
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
Forum Library, Charter, Moderators: coopster & jatar k

PHP Server Side Scripting Forum

    
Unable to change profile image.
Scotty13




msg:4451819
 1:52 pm on May 10, 2012 (gmt 0)

I'm only a rookie, so I would appreciate any help and please don't answer with to complicated replies.

Error coming from line 82 (marked below along with script entry).

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

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


// ------- 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";
LINE 82: $place_file = move_uploaded_file( $_FILES['fileField']['tmp_name'], "tktedmembers/$id/".$newname);
}
}
}
// ------- END PARSING PICTURE UPLOAD ---------

I tried everything that "I" could think of.

Thanks, Scott

 

rainborick




msg:4451852
 3:15 pm on May 10, 2012 (gmt 0)

It looks like the path to the destination for move_uploaded_file() is incomplete. I'd recommend using the complete path, as in:

$place_file = move_uploaded_file( $_FILES['fileField']['tmp_name'], $_SERVER['DOCUMENT_ROOT'] . "/tktedmembers/$id/".$newname);

Of course, you may have to add any additional directories in the path to 'tktedmembers/' as well.

rocknbil




msg:4451873
 3:56 pm on May 10, 2012 (gmt 0)

also trap that bugger, make sure it exists:

else {
$newname = "image01.jpg";

if (is_dir($_SERVER['DOCUMENT_ROOT'] . "/tktedmembers/$id") and is_writable($_SERVER['DOCUMENT_ROOT'] . "/tktedmembers/$id")) {

$place_file = move_uploaded_file( $_FILES['fileField']['tmp_name'], $_SERVER['DOCUMENT_ROOT'] ."tktedmembers/$id/".$newname);
}
else {
echo $_SERVER['DOCUMENT_ROOT'] . "/tktedmembers/$id/" is not a directory or is not writable.";
exit;
}


}

Inside that else, you could also add some bits to attempt to create the $id directory, then finally dump out if that fails.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / PHP Server Side Scripting
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved