This is a read-only archive of the old Scratch 1.x Forums.
Try searching the current Scratch discussion forums.

#1 2011-10-06 13:11:05

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

PHP File extensions?

I don't get it. I have this code:

Code:

<?php
if ((($_FILES["file"]["type"] == "mu1"))
&& ($_FILES["file"]["size"] < 20000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo "Upload: " . $_FILES["file"]["name"] . "<br />";
    echo "Type: " . $_FILES["file"]["type"] . "<br />";
    echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";

    if (file_exists("upload/" . $_FILES["file"]["name"]))
      {
      echo $_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "upload/" . $_FILES["file"]["name"]);
      echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo "Invalid file";
  }
?>

But hwen you upload a .mu1 file it says: Invalid file.


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#2 2011-10-06 21:13:06

Magnie
Scratcher
Registered: 2007-12-12
Posts: 1000+

Re: PHP File extensions?

Code:

if ((($_FILES["file"]["type"] == "mu1"))
&& ($_FILES["file"]["size"] < 20000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }

That's basically saying: If file type is .mu1 and it is less than 20000 in whatever size ( I'm assuming bytes ) then move on and check if there are errors, and if there are, it prints them, if not then it uploads the file ( I think ). Though the error you are getting means the file is either to big, or it is not a mu1 file.

Try creating a notepad file with a few letters add the .mu1 extension and try uploading it. Scratch project sizes will be bigger 20000 bytes, or at least projects with more than two sprites (depending on the scripts and images).

Offline

 

#3 2011-10-06 23:44:51

meowmeow55
Scratcher
Registered: 2008-12-24
Posts: 1000+

Re: PHP File extensions?

The file type is a MIME type, not an extension. If you want an extension to be read, use this code:

Code:

$filename = strtolower($_FILES["file"]["name"]) ; 
$exts = split("[/\\.]", $filename) ; 
$n = count($exts)-1; 
$exts = $exts[$n];
if ($exts == "mu1")
&& ($_FILES["file"]["size"] < 20000))
//etc.

Yawn.

Offline

 

#4 2011-10-06 23:50:17

ssss
Scratcher
Registered: 2007-07-29
Posts: 1000+

Re: PHP File extensions?

meowmeow55 wrote:

The file type is a MIME type, not an extension. If you want an extension to be read, use this code:

Code:

$filename = strtolower($_FILES["file"]["name"]) ; 
$exts = split("[/\\.]", $filename) ; 
$n = count($exts)-1; 
$exts = $exts[$n];
if ($exts == "mu1")
&& ($_FILES["file"]["size"] < 20000))
//etc.

lol.  That would be a problem, wouldn't it?

(P.S. Get on your site! :p )


Hey.  It's me SSSS, back from the dead!  smile

Offline

 

#5 2011-10-07 11:16:11

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: PHP File extensions?

ssss wrote:

meowmeow55 wrote:

The file type is a MIME type, not an extension. If you want an extension to be read, use this code:

Code:

$filename = strtolower($_FILES["file"]["name"]) ; 
$exts = split("[/\\.]", $filename) ; 
$n = count($exts)-1; 
$exts = $exts[$n];
if ($exts == "mu1")
&& ($_FILES["file"]["size"] < 20000))
//etc.

lol.  That would be a problem, wouldn't it?

(P.S. Get on your site! :p )

Parse error: syntax error, unexpected T_BOOLEAN_AND in /home/a5292800/public_html/share.php on line 28?


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#6 2011-10-07 11:26:44

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: PHP File extensions?

^^ Just add brackets... anazyle the errors before you post them!

Offline

 

#7 2011-10-07 11:33:39

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: PHP File extensions?

LS97 wrote:

^^ Just add brackets... anazyle the errors before you post them!

I'm still getting the message.


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#8 2011-10-07 11:52:01

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: PHP File extensions?

WindowsExplorer wrote:

LS97 wrote:

^^ Just add brackets... anazyle the errors before you post them!

I'm still getting the message.

Look, the code that meowmeow gave you is incomplete, meaning you obviously have to go through it and adapt it as well as adding your bit to it. So adapt it, and then see if it still gives you the error.

Offline

 

#9 2011-10-07 11:54:48

meowmeow55
Scratcher
Registered: 2008-12-24
Posts: 1000+

Re: PHP File extensions?

WindowsExplorer wrote:

LS97 wrote:

^^ Just add brackets... anazyle the errors before you post them!

I'm still getting the message.

Post your entire code after you added the bit I posted. You probably just put it in wrong.
Edit: Oh wait, there's an extra parenthetical missing. The code I used didn't have a size limit, so it didn't need that. Try this:

Code:

$filename = strtolower($_FILES["file"]["name"]) ; 
$exts = split("[/\\.]", $filename) ; 
$n = count($exts)-1; 
$exts = $exts[$n];
if ((($exts == "mu1"))
&& ($_FILES["file"]["size"] < 20000))
//etc.

Last edited by meowmeow55 (2011-10-07 11:57:14)


Yawn.

Offline

 

#10 2011-10-07 13:29:06

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: PHP File extensions?

Code:

$filename = strtolower($_FILES["file"]["name"]) ; 
$exts = split("[/\\.]", $filename) ; 
$n = count($exts)-1; 
$exts = $exts[$n];
if ($exts == "mu1")
(&& ($_FILES["file"]["size"] < 20000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    if (file_exists("planets/" . $_FILES["file"]["name"]))
      {
      echo "Your planet " . $_FILES["file"]["name"] . " has already been shared. Try using a different name.";
      }
    else
      {
      $ip = $_SERVER['REMOTE_ADDR'];
      $name = $_POST['project_name'];
      $file = $_FILES["file"]["name"];
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "planets/" . $_FILES["file"]["name"]);
      echo "<p>Your planet has been shared! You may download it <a href=\"" . "planets/" . $_FILES["file"]["name"] . "\">here</a>!</p>";
      mysql_query("INSERT INTO project_details (name, file, creator)
VALUES ('$name', '$file', '$ip')");
      }
    }
  }
else
  {
  echo "<p>Please only share MU1 files. Sharing other file types could get your account ban.</p>";
  }
?>

http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#11 2011-10-07 15:16:01

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: PHP File extensions?

WindowsExplorer wrote:

Code:

$filename = strtolower($_FILES["file"]["name"]) ; 
$exts = split("[/\\.]", $filename) ; 
$n = count($exts)-1; 
$exts = $exts[$n];
if ($exts == "mu1")
(&& ($_FILES["file"]["size"] < 20000))
  {
  if ($_FILES["file"]["error"] > 0)
    {
    echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    if (file_exists("planets/" . $_FILES["file"]["name"]))
      {
      echo "Your planet " . $_FILES["file"]["name"] . " has already been shared. Try using a different name.";
      }
    else
      {
      $ip = $_SERVER['REMOTE_ADDR'];
      $name = $_POST['project_name'];
      $file = $_FILES["file"]["name"];
      move_uploaded_file($_FILES["file"]["tmp_name"],
      "planets/" . $_FILES["file"]["name"]);
      echo "<p>Your planet has been shared! You may download it <a href=\"" . "planets/" . $_FILES["file"]["name"] . "\">here</a>!</p>";
      mysql_query("INSERT INTO project_details (name, file, creator)
VALUES ('$name', '$file', '$ip')");
      }
    }
  }
else
  {
  echo "<p>Please only share MU1 files. Sharing other file types could get your account ban.</p>";
  }
?>

[disparaging image removed by moderator - please be polite]
[fine, fine... what does disparaging even mean anyway  tongue  -LS97]


Since when do you put brackets next to "and" operators?
Did you ever take that tutorial I recommended?

If you didn't, and if you don't know anything about programming at all, then translate it to english. Your "sentence" hakes to freakin' sense...

if ($exts == "mu1") (&& ($_FILES["file"]["size"] < 20000))

(if exts equals mu1), (and file's size is less than 20000)

Last edited by LS97 (2011-10-07 17:30:20)

Offline

 

#12 2011-10-07 15:54:10

WindowsExplorer
Scratcher
Registered: 2011-02-25
Posts: 1000+

Re: PHP File extensions?

YES BUT I TRIED EVERYTHING AND NOTHING WORKED. IT ALWAYS GIVES ME A PHP ERROR OR SAYS PLEASE ONLY SHARE MU1 FILES. And what is the link to that guid? If it was w3school's well, I was using THEIR code.


http://i.imgur.com/H6LLdnK.pnghttp://i.imgur.com/VYuD7BY.png

Offline

 

#13 2011-10-07 17:29:20

LS97
Scratcher
Registered: 2009-06-14
Posts: 1000+

Re: PHP File extensions?

WindowsExplorer wrote:

YES BUT I TRIED EVERYTHING AND NOTHING WORKED. IT ALWAYS GIVES ME A PHP ERROR OR SAYS PLEASE ONLY SHARE MU1 FILES. And what is the link to that guid? If it was w3school's well, I was using THEIR code.

Nope, php.net.

Offline

 

Board footer