Upload File (Song)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
dclamp
Forum Commoner
Posts: 35
Joined: Sun Sep 17, 2006 10:05 am

Upload File (Song)

Post by dclamp »

Hello. I am having trouble with my upload code. It keeps returing a php chmod error "File Does Not Exist"

here is my code:

Code: Select all

// upload
		$org_file_name=$_FILE["mp3file"]["name"];
		$temp_file_name=$_FILE["mp3file"]["tmp_name"];
		
		$file_name = $member_id . "-" . $org_file_name;
		$song_url = "songs/" . $file_name;
		$result = move_uploaded_file($temp_file_name, $song_url);
		$res = chmod($song_url, 0755);
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Have you verified that the file it is referencing does exist?
User avatar
dclamp
Forum Commoner
Posts: 35
Joined: Sun Sep 17, 2006 10:05 am

Post by dclamp »

yes. and it does not exist. Forgot to include this in the first post.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

You should not only store the result of move_uploaded_file but check it for true or false.
try

Code: Select all

error_reporting(E_ALL); ini_set('display_errors', true);

$org_file_name=$_FILE["mp3file"]["name"];
$temp_file_name=$_FILE["mp3file"]["tmp_name"];

$file_name = $member_id . "-" . $org_file_name;
$song_url = "songs/" . $file_name;
$result = move_uploaded_file($temp_file_name, $song_url);
if ( false===$result ) {
	die("failed to move uploaded file to '$song_url'");
}
$res = chmod($song_url, 0755);
User avatar
dclamp
Forum Commoner
Posts: 35
Joined: Sun Sep 17, 2006 10:05 am

Post by dclamp »

ok. with the code that you gave me, i am getting these errors:

Code: Select all

Notice: Undefined variable: _FILE in /home/jphendr/public_html/beta/edit_mprofile1.php on line 225

Notice: Undefined variable: _FILE in /home/jphendr/public_html/beta/edit_mprofile1.php on line 226
failed to move uploaded file to 'songs/4-'
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

the superglobal you're trying to use is $_FILES <-- notice the "S" on the end, as it's plural.

Cheers,
Kieran
User avatar
dclamp
Forum Commoner
Posts: 35
Joined: Sun Sep 17, 2006 10:05 am

Post by dclamp »

ok. now i am getting this error:

Code: Select all

failed to move uploaded file to 'songs/5109-I Touch Myself.mp3'
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

is songs/ directory accessible and have permissions?
User avatar
dclamp
Forum Commoner
Posts: 35
Joined: Sun Sep 17, 2006 10:05 am

Post by dclamp »

Jcart wrote:is songs/ directory accessible and have permissions?
it is 777.
User avatar
Kieran Huggins
DevNet Master
Posts: 3635
Joined: Wed Dec 06, 2006 4:14 pm
Location: Toronto, Canada
Contact:

Post by Kieran Huggins »

Just a wild stab in the dark here, but is the songs directory directly beneath where the script is executing from?

Also try the same path with a preceding ./ - just to be safe.

If it's still broken, check:
  • is the disk full?
    have you exeeded your disk qouta?
    are you exceeding your max_execution_time?
    are you exceeding your post_max_size?
    do you have divinyls_uploads enabled?
Then I'd start debugging by putting a few files in that directory manually and trying to list the directory from within the script.

Cheers,
Kieran
Post Reply