Jump to content


Photo

Uploading Script Problem


  • Please log in to reply
7 replies to this topic

#1 elementz

elementz
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 31 March 2006 - 05:34 AM

<? 
//ob_start(); 
//the above line needs to be above ALL HTML and PHP (except for <?). 
//include("config.php"); 
//gets the config page, which connects to the database and gets the user's information 
//if ($logged[username]) 
//{ 
//checks to see if they are logged in 
switch($_GET[song]) 
{ 
//this allows us to use one page for the entire thing 
default: 
break; 

case 'upload':
echo ("<form action=\"song.php?song=add\" enctype=\"multipart/form-data\" method=\"post\"><br />
Select file
<input name=\"ufile\" type=\"file\" size=\"50\">
<input type=\"submit\" name=\"Upload\" value=\"Upload\">
</form>");
 
break;

case 'add':
$valid = array (".mp3",".wma");

$type = strtolower(strstr($filename, '.'));
if (!in_array($type, $valid)) {
echo ("The submitted file was of invalid type.<br />");
}
 
$file_name = $HTTP_POST_FILES['ufile']['name'];
$random_digit=rand(00000000,99999999);
$new_file_name=$file_name.$random_digit;

//set where you want to store files
//in this example we keep file in folder upload 
//$new_file_name = new upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path= "songs/".$new_file_name;
if($ufile !=none)
{
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
{
echo ("Successful<BR />"); 

//$new_file_name = new file name
//$HTTP_POST_FILES['ufile']['size'] = file size
//$HTTP_POST_FILES['ufile']['type'] = type of file
echo ("File Name :".$new_file_name."<BR />0");
echo ("File Size :".$HTTP_POST_FILES['ufile']['size']."<BR />"); 
echo ("File Type :".$HTTP_POST_FILES['ufile']['type']."<BR />"); 
}
else
{
echo ("Error");
}
}
break; 
} 
echo("<br /><br /><a href=\"song.php?song=upload\">Add</a></b>");
?>

This is my code, but when I go to upload a song on it, it takes a while as if it is uploading it but then it comes up with the page "Cannot Connect To Server".

Thankyou,
Luke

#2 elementz

elementz
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 31 March 2006 - 06:54 AM

[!--quoteo(post=360267:date=Mar 31 2006, 04:34 PM:name=elementz)--][div class=\'quotetop\']QUOTE(elementz @ Mar 31 2006, 04:34 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
<? 
//ob_start(); 
//the above line needs to be above ALL HTML and PHP (except for <?). 
//include("config.php"); 
//gets the config page, which connects to the database and gets the user's information 
//if ($logged[username]) 
//{ 
//checks to see if they are logged in 
switch($_GET[song]) 
{ 
//this allows us to use one page for the entire thing 
default: 
break; 

case 'upload':
echo ("<form action=\"song.php?song=add\" enctype=\"multipart/form-data\" method=\"post\"><br />
Select file
<input name=\"ufile\" type=\"file\" size=\"50\">
<input type=\"submit\" name=\"Upload\" value=\"Upload\">
</form>");
 
break;

case 'add':
$valid = array (".mp3",".wma");

$type = strtolower(strstr($filename, '.'));
if (!in_array($type, $valid)) {
echo ("The submitted file was of invalid type.<br />");
}
 
$file_name = $HTTP_POST_FILES['ufile']['name'];
$random_digit=rand(00000000,99999999);
$new_file_name=$file_name.$random_digit;

//set where you want to store files
//in this example we keep file in folder upload 
//$new_file_name = new upload file name
//for example upload file name cartoon.gif . $path will be upload/cartoon.gif
$path= "songs/".$new_file_name;
if($ufile !=none)
{
if(copy($HTTP_POST_FILES['ufile']['tmp_name'], $path))
{
echo ("Successful<BR />"); 

//$new_file_name = new file name
//$HTTP_POST_FILES['ufile']['size'] = file size
//$HTTP_POST_FILES['ufile']['type'] = type of file
echo ("File Name :".$new_file_name."<BR />0");
echo ("File Size :".$HTTP_POST_FILES['ufile']['size']."<BR />"); 
echo ("File Type :".$HTTP_POST_FILES['ufile']['type']."<BR />"); 
}
else
{
echo ("Error");
}
}
break; 
} 
echo("<br /><br /><a href=\"song.php?song=upload\">Add</a></b>");
?>

This is my code, but when I go to upload a song on it, it takes a while as if it is uploading it but then it comes up with the page "Cannot Connect To Server".

Thankyou,
Luke
[/quote]

bump

#3 elementz

elementz
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 31 March 2006 - 10:10 AM

[!--quoteo(post=360272:date=Mar 31 2006, 05:54 PM:name=elementz)--][div class=\'quotetop\']QUOTE(elementz @ Mar 31 2006, 05:54 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
bump
[/quote]

help please :D

#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 31 March 2006 - 10:22 AM

Are you using a database? If you do can you show us the code use for:
- connecting to database server
- selecting database, and
- when you query the database.

#5 elementz

elementz
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 31 March 2006 - 10:29 AM

[!--quoteo(post=360311:date=Mar 31 2006, 09:22 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Mar 31 2006, 09:22 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
Are you using a database? If you do can you show us the code use for:
- connecting to database server
- selecting database, and
- when you query the database.
[/quote]

Nope, I am just testing the uploading script. Thats why I have commented out the user system. Could it be to do with the server?

Thankyou,
Luke

#6 lpxxfaintxx

lpxxfaintxx
  • Members
  • PipPipPip
  • Advanced Member
  • 181 posts

Posted 31 March 2006 - 11:50 AM

Are you on a free shared hosting plan? They might not allow mp3s files.

#7 elementz

elementz
  • Members
  • PipPipPip
  • Advanced Member
  • 36 posts

Posted 31 March 2006 - 12:00 PM

nope reseller. Could it still be the host? Cause the host doesn't allow me the chmod files to 777 only 755, could that be the problem?

#8 bqallover

bqallover
  • Members
  • PipPipPip
  • Advanced Member
  • 111 posts
  • LocationLeeds, UK

Posted 31 March 2006 - 02:21 PM

[!--quoteo(post=360330:date=Mar 31 2006, 01:00 PM:name=elementz)--][div class=\'quotetop\']QUOTE(elementz @ Mar 31 2006, 01:00 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
nope reseller. Could it still be the host? Cause the host doesn't allow me the chmod files to 777 only 755, could that be the problem?
[/quote]

Sounds like that is your problem. If your upload directory is 755, then I think I'm right in saying your script can't write to it. I had a very similar problem on a test machine yesterday and chmod'ing to 777 fixed the script and allowed the uploads.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users