ionik Posted February 26, 2008 Share Posted February 26, 2008 Ok why doesnt the file upload? It doesnt give any errors execpt the die_message error at the end and i cant fiqure out the problem heres the function, all the constants are defined when the script is run and the AVATAR_UPLOAD_DIR = 'includes/uploads/avatars/' and i've made it so when the file is uploaded it will be given a random name from my session_id_create() function so names will be d0951a6f.gif ETC, this is ran on my localhost server on my pc....so permissions is not the problem and if i use my test file and simply use move_uploaded_file() it works.... function upload_profile_image($name, $type) { global $db,$udata; if(!$_POST['form']) { die_message(USER_MESSAGE, 'Unauthorized'); } if(empty($_FILES)) { die_message(USER_MESSAGE, 'No file was selected to upload'); } // Information about uploading file $info = getimagesize($_FILES[$name]['tmp_name']); $allowed_ext_array = explode(',', ALLOWED_IMAGE_TYPES); foreach($allowed_ext_array as $allowed_ext) { $strlen = strlen($allowed_ext) - 6; $names .= ' '.substr($allowed_ext, '6', $strlen); } if(!in_array($_FILES[$name]['type'], $allowed_ext_array)) { die_message(USER_MESSAGE, 'Sorry, you are only allowed to upload '.$names.' file types'); } $max_size = iif($type == 'avatar', ALLOWED_AVATAR_SIZE, ALLOWED_PICTURE_SIZE); $max_width = iif($type == 'avatar', MAX_AVATAR_WIDTH, MAX_PICTURE_WIDTH); $max_height = iif($type == 'avatar', MAX_AVATAR_HEIGHT, MAX_PICTURE_HEIGHT); $upload_dir = iif($type == 'avatar', AVATAR_UPLOAD_DIR, PICTURES_UPLOAD_DIR); if($info[0] > $max_width) { die_message(USER_MESSAGE, 'Sorry avatars are only allowed a maximum width of '.$max_width); } if($info[1] > $max_height) { die_message(USER_MESSAGE, 'Sorry avatars are only allowed a maximum height of '.$max_height); } if($_FILES[$name]['size'] > $max_size) { $size = $max_size * 100; die_message(USER_MESSAGE, 'Sorry avatars are only allowed a maximum size of '.$size.' kb'); } $file_type = substr($_FILES[$name]['type'], 6, strlen($_FILES[$name]['type']) - 6); $name = substr(session_id_create(), 0, . '.' . $file_type; $named = $upload_dir . $name; if(move_uploaded_file($_FILES[$name]['tmp_name'], $named)) { $table = iif($type == 'avatar', 'avatar', 'picture'); die_message(USER_MESSAGE, 'File has been uploaded and saved'); } else { die_message(USER_MESSAGE, 'Failed to upload file please try again <a href="#" onclick="javascript:history.go(-1)"'); } } Link to comment https://forums.phpfreaks.com/topic/93107-uploading-file-script-problem/ Share on other sites More sharing options...
rhodesa Posted February 26, 2008 Share Posted February 26, 2008 Try this...right before this line: if(move_uploaded_file($_FILES[$name]['tmp_name'], $named)) add this code: if(!is_dir($upload_dir)) die_message(USER_MESSAGE,"Upload dir does not exist: $upload_dir"); if(!is_writable($upload_dir)) die_message(USER_MESSAGE,"Upload dir is not writable: $upload_dir"); also, in your last die_message, add the file you are trying to move to make sure it's what you are expecting: die_message(USER_MESSAGE, 'Failed to upload file to '$named' please try again <a href="#" onclick="javascript:history.go(-1)"'); Link to comment https://forums.phpfreaks.com/topic/93107-uploading-file-script-problem/#findComment-477056 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.