Jump to content

Archived

This topic is now archived and is closed to further replies.

elementz

Uploading Script Problem

Recommended Posts

[code]<?
//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>");
?>[/code]

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

Share this post


Link to post
Share on other sites
[!--quoteo(post=360267:date=Mar 31 2006, 04:34 PM:name=elementz)--][div class=\'quotetop\']QUOTE(elementz @ Mar 31 2006, 04:34 PM) [snapback]360267[/snapback][/div][div class=\'quotemain\'][!--quotec--]
[code]<?
//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>");
?>[/code]

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

Share this post


Link to post
Share on other sites
[!--quoteo(post=360272:date=Mar 31 2006, 05:54 PM:name=elementz)--][div class=\'quotetop\']QUOTE(elementz @ Mar 31 2006, 05:54 PM) [snapback]360272[/snapback][/div][div class=\'quotemain\'][!--quotec--]
bump
[/quote]

help please :D

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[!--quoteo(post=360311:date=Mar 31 2006, 09:22 PM:name=wildteen88)--][div class=\'quotetop\']QUOTE(wildteen88 @ Mar 31 2006, 09:22 PM) [snapback]360311[/snapback][/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

Share this post


Link to post
Share on other sites
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?

Share this post


Link to post
Share on other sites
[!--quoteo(post=360330:date=Mar 31 2006, 01:00 PM:name=elementz)--][div class=\'quotetop\']QUOTE(elementz @ Mar 31 2006, 01:00 PM) [snapback]360330[/snapback][/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.

Share this post


Link to post
Share on other sites

×

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.