Jump to content

Recommended Posts

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]

Link to comment
https://forums.phpfreaks.com/topic/70972-solved-problem-with-upload/
Share on other sites

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

 

 

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

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;
}
		}

}
?>

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;
}
		}

}
?>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.