Welcome to WebmasterWorld Guest from 23.21.38.201

Forum Moderators: coopster & jatar k

Parsing Picture Upload Not Uploading

   
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
7:44 am on Apr 24, 2012 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



Have you checked is the destination path valid "tktedmembers/$id/".$newname and accessible? And you may want to give an absolute path.
4:06 pm on Apr 24, 2012 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



^ ^ 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)
 

Featured Threads

My Threads

Hot Threads This Week

Hot Threads This Month