Hej udviklere.
Jeg sidder og er igang med at lave et uploadings system til et projekt jeg har lavet.
Det skal være muligt for brugeren at uploade et billede til en mappe han har i FTP'en.
Men billedet ligger sig forkert, selvom stien er lavet rigtigt:
- // connect to database
- include ('db.php');
-
- $query = "SELECT * FROM users WHERE id='$id'";
- $result = mysql_query($query);
- $row = mysql_fetch_array(mysql_query($query));
- $username = $row['username'];
-
- $upload_dir = '../../../uploads/images/'.$username.'/';
- $allowed_ext = array('jpg','jpeg','png','gif');
-
-
- if(strtolower($_SERVER['REQUEST_METHOD']) != 'post'){
- exit_status('Error! Wrong HTTP method!');
- }
-
-
- if(array_key_exists('pic',$_FILES) && $_FILES['pic']['error'] == 0 ){
-
- $pic = $_FILES['pic'];
-
- if(!in_array(get_extension($pic['name']),$allowed_ext)){
- exit_status('Only '.implode(',',$allowed_ext).' files are allowed!');
- }
-
- if($demo_mode){
-
- // File uploads are ignored. We only log them.
-
- $line = implode(' ', array( date('r'), $_SERVER['REMOTE_ADDR'], $pic['size'], $pic['name']));
- file_put_contents('log.txt', $line.PHP_EOL, FILE_APPEND);
-
- exit_status('Uploads are ignored in demo mode.');
- }
-
-
- // Move the uploaded file from the temporary
- // directory to the uploads folder:
-
- if(move_uploaded_file($pic['tmp_name'], $upload_dir.$pic['name'])){
- exit_status('File was uploaded successfuly!');
- }
-
- }
-
- exit_status('Something went wrong with your upload!');
-
-
- // Helper functions
-
- function exit_status($str){
- echo json_encode(array('status'=>$str));
- exit;
- }
-
- function get_extension($file_name){
- $ext = explode('.', $file_name);
- $ext = array_pop($ext);
- return strtolower($ext);
- }
Kan nogen finde fejlen og hjælpe mig her, billedet ligger sig i mappen "uploads/images" og ikke "uploads/images/username" som jeg gerne vil have den til.