corillo181 Posted September 27, 2007 Share Posted September 27, 2007 i got this code, but file is not been move to the directory that i gave it any one know why the copy functions is not working. <?php function newSong($tmpName,$fileName,$fileType,$newName,$genre_id,$artist_id,$save){ $tmpPath = $tmpName; $songName = $fileName; $filetype = $fileType; $ext = strtolower(substr($songName,-4)); $newName = addslashes($newName); $nameNew = str_replace(' ','_',$newName.'.mp3'); if(empty($newName)){ $this->display = "you left the name empty"; return false; }elseif($ext != '.mp3'){ $this->display = "$ext is not a mp3"; return false; }elseif(empty($artist_id)){ $this->display = "You did not picked a artist"; return false; }else{ if(file_exists($nameNew)){ $this->display = "that song name already exists"; return false; }else{ // THIS IS NOT WORKING CAN SOME ONE TELL ME WHY? IT RETURNS FALSE if(!copy($tmpPath,$save.$nameNew)){ $this->display = "the file was not uploaded"; return false; }else{ $path=$save.$nameNew; $query = "INSERT INTO tra_artist_song(genre_id,artist_id,song_name,song_path,date)VALUES('{$genre_id}','{$artist_id}','{$newName}','$path',NOW())"; $this->db->query($query); $this->display = "the song was succesfully uploaded"; return true; } } } } ?> [code] [/code] Quote Link to comment https://forums.phpfreaks.com/topic/70972-solved-problem-with-upload/ Share on other sites More sharing options...
d22552000 Posted September 27, 2007 Share Posted September 27, 2007 is it just me or does this script pull $save out of its ass...? if(!copy($tmpPath,$save.$nameNew)){ I never saw "$save" anywhere in the document... (BEFORE THIS CODE) Quote Link to comment https://forums.phpfreaks.com/topic/70972-solved-problem-with-upload/#findComment-356824 Share on other sites More sharing options...
freakstyle Posted September 27, 2007 Share Posted September 27, 2007 Hey there, i'm not sure where to start in on this one, sorry. i'll try though.... so 1. is this inside a class? 1a. if it is, please post entire class and an example of how you are using it 1b. if it is not, then why are you using $this ? 2. what do you intend this to do : if(!copy($tmpPath,$save.$nameNew)){ the save var was never created, maybe it was passed into this function, but we don't see that so what should it be? 3. there is no need to reset your variable names, this is not only messy but distracting. <?php function newSong($tmpName,$fileName,$fileType,$newName,$genre_id,$artist_id,$save){ $tmpPath = $tmpName; $songName = $fileName; $filetype = $fileType; } // works just as well (just match your vars you use in the function with the function parameters // after all, they are parameters for your function, why assign them to another variable right off the bat? function newSong($tmpName,$fileName,$fileType,$newName,$genre_id,$artist_id,$save){ } if you are writing your own class for to handle this, you should try to break out that logic, make a class that handles the file functions, one for the db (looks like you have a db method already, should be easy enough to move into its own class) ref: http://us2.php.net/manual/en/features.file-upload.php good luck Quote Link to comment https://forums.phpfreaks.com/topic/70972-solved-problem-with-upload/#findComment-356841 Share on other sites More sharing options...
corillo181 Posted September 28, 2007 Author Share Posted September 28, 2007 No offense d-numbers, but if you did not saw save before that, you shouldn't be trying to help people out in this forum. however, FreakStyle it is a big class dived into a lot of sections, but this one doe snot need any interaction from any other objec tin the class to work. i made the code work, by changing the directory i was using a full directory to upload the file http://www.my.com/directory/upload i had to change it to directory/upload/ how ever now when i try to view the file after been uploaded. http://www.my.com/directory/upload/new.mp3 when i pastel it into my browser it says 403 Forbidden any reason why i would be getting a forbidden from a file that is uploaded to a directory where the mod is 777 Quote Link to comment https://forums.phpfreaks.com/topic/70972-solved-problem-with-upload/#findComment-356954 Share on other sites More sharing options...
corillo181 Posted September 28, 2007 Author Share Posted September 28, 2007 i found the problem it seens that my upload method is not uploading the file as a sound. can any one tell me why this is happening? how can i make it so so that my song is uploaded as sound type here is the code again <?php // NOT UPLOADING AS A Sound TYPE function newSong($tmpName,$fileName,$fileType,$newName,$genre_id,$artist_id,$save){ $ext = strtolower(substr($fileName,-4)); $newName = addslashes($newName); $nameNew = str_replace(' ','_',$newName.'.mp3'); if(empty($newName)){ $this->display = "you left the name empty"; return false; }elseif($ext != '.mp3'){ $this->display = "$ext is not a mp3"; return false; }elseif(empty($artist_id)){ $this->display = "You did not picked a artist"; return false; }elseif(file_exists($nameNew)){ $this->display = "that song name already exists"; return false; }elseif(!is_dir($save)){ $this->display = "$save is not a directory"; return false; }else{ if(!move_uploaded_file($tmpName,$save.$nameNew)){ $this->display = $save.$nameNew."the file was not uploaded"; return false; }else{ $path=$save.$nameNew; $query = "INSERT INTO tra_artist_song(genre_id,artist_id,song_name,song_path,date)VALUES('{$genre_id}','{$artist_id}','{$newName}','$path',NOW())"; $this->db->query($query); $this->display = "the song was succesfully uploaded"; return true; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/70972-solved-problem-with-upload/#findComment-356976 Share on other sites More sharing options...
corillo181 Posted September 28, 2007 Author Share Posted September 28, 2007 no brave ones tonight? Quote Link to comment https://forums.phpfreaks.com/topic/70972-solved-problem-with-upload/#findComment-356991 Share on other sites More sharing options...
corillo181 Posted September 28, 2007 Author Share Posted September 28, 2007 i found the problem it seens that my upload method is not uploading the file as a sound. can any one tell me why this is happening? how can i make it so so that my song is uploaded as sound type here is the code again <?php // NOT UPLOADING AS A Sound TYPE function newSong($tmpName,$fileName,$fileType,$newName,$genre_id,$artist_id,$save){ $ext = strtolower(substr($fileName,-4)); $newName = addslashes($newName); $nameNew = str_replace(' ','_',$newName.'.mp3'); if(empty($newName)){ $this->display = "you left the name empty"; return false; }elseif($ext != '.mp3'){ $this->display = "$ext is not a mp3"; return false; }elseif(empty($artist_id)){ $this->display = "You did not picked a artist"; return false; }elseif(file_exists($nameNew)){ $this->display = "that song name already exists"; return false; }elseif(!is_dir($save)){ $this->display = "$save is not a directory"; return false; }else{ if(!move_uploaded_file($tmpName,$save.$nameNew)){ $this->display = $save.$nameNew."the file was not uploaded"; return false; }else{ $path=$save.$nameNew; $query = "INSERT INTO tra_artist_song(genre_id,artist_id,song_name,song_path,date)VALUES('{$genre_id}','{$artist_id}','{$newName}','$path',NOW())"; $this->db->query($query); $this->display = "the song was succesfully uploaded"; return true; } } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/70972-solved-problem-with-upload/#findComment-357483 Share on other sites More sharing options...
BlueSkyIS Posted September 28, 2007 Share Posted September 28, 2007 how can i make it so so that my song is uploaded as sound type here is the code again there is nothing special to do to "make it so so that my song is uploaded as sound type". Quote Link to comment https://forums.phpfreaks.com/topic/70972-solved-problem-with-upload/#findComment-357485 Share on other sites More sharing options...
corillo181 Posted September 28, 2007 Author Share Posted September 28, 2007 so why when i upload it and i try to view the file it gives me a forbidden. i try using the websites normal file upload and when i do it that way the file is not presented in a forbidden page. Quote Link to comment https://forums.phpfreaks.com/topic/70972-solved-problem-with-upload/#findComment-357514 Share on other sites More sharing options...
BlueSkyIS Posted September 28, 2007 Share Posted September 28, 2007 are the permissions on the file correct so that you have permission to see it? maybe look into chmod() Quote Link to comment https://forums.phpfreaks.com/topic/70972-solved-problem-with-upload/#findComment-357517 Share on other sites More sharing options...
corillo181 Posted September 28, 2007 Author Share Posted September 28, 2007 the folder is 777 so the mod is good. Quote Link to comment https://forums.phpfreaks.com/topic/70972-solved-problem-with-upload/#findComment-357526 Share on other sites More sharing options...
corillo181 Posted September 28, 2007 Author Share Posted September 28, 2007 oh thanx blueSky i was too much into the folder, but forgot about the file, the file was not 777. Quote Link to comment https://forums.phpfreaks.com/topic/70972-solved-problem-with-upload/#findComment-357527 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.