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

PHP Server Side Scripting Forum

    
Parsing Picture Upload Not Uploading
Scotty13




msg:4442682
 10:12 pm on Apr 18, 2012 (gmt 0)

ERROR:
Warning: move_uploaded_file(tktedmembers/6/image01.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/myglobal/public_html/edit_res.php on line 92 (marked below)
Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpzPTsIn' to 'tktedmembers/6/image01.jpg' in /home/myglobal/public_html/edit_res.php on line 92


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

Thanks in advance

 

enigma1




msg:4444562
 7:44 am on Apr 24, 2012 (gmt 0)

Have you checked is the destination path valid "tktedmembers/$id/".$newname and accessible? And you may want to give an absolute path.

rocknbil




msg:4444726
 4:06 pm on Apr 24, 2012 (gmt 0)

^ ^ Precisely. :-)

This is the exact same issue discussed in your other thread a few days ago. Instead of

tktedmembers/$id/".$newname

$_SERVER['DOCUMENT_ROOT'] . "/tktedmembers/$id/$newname"

(Note that scalar variables will interpolate when double quoted, eliminating some of the concatenation

Make sure the directory exists and it's writable (file permissions.) You should use a good error trap here:

if (is_dir($_SERVER['DOCUMENT_ROOT'] . "/tktedmembers/$id") and is_writable($_SERVER['DOCUMENT_ROOT'] . "/tktedmembers/$id")) {
// do it
}
else {
die("OOPS! " . $_SERVER['DOCUMENT_ROOT'] . \"/tktedmembers/$id/$newname\" is not a directory OR if it is, it's not writable.");
}

is_writable() [php.net]
is_dir() [php.net] (also is_file will be useful at some point in any upload scheme)

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.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved