Jump to content

[SOLVED] A php code for upload script of max 5 MB flash file


SwapsRulez

Recommended Posts

Hi there, i'm working for an application where i do need to create an upload page where user can upload the .swf files only & that file must be less than or equal to 5 mb. i've created the site using html. but i'm new to php & that's why searched it on the google.

 

it returned the following code...

 

<?php
//Сheck that we have a file
if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {
  //Check if the file is JPEG image and it's size is less than 350Kb
  $filename = basename($_FILES['uploaded_file']['name']);
  $ext = substr($filename, strrpos($filename, '.') + 1);
  if (($ext == "jpg") && ($_FILES["uploaded_file"]["type"] == "image/jpeg") && 
    ($_FILES["uploaded_file"]["size"] < 350000)) {
    //Determine the path to which we want to save this file
      $newname = dirname(__FILE__).'/upload/'.$filename;
      //Check if the file with the same name is already exists on the server
      if (!file_exists($newname)) {
        //Attempt to move the uploaded file to it's new place
        if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {
           echo "It's done! The file has been saved as: ".$newname;
        } else {
           echo "Error: A problem occurred during file upload!";
        }
      } else {
         echo "Error: File ".$_FILES["uploaded_file"]["name"]." already exists";
      }
  } else {
     echo "Error: Only .jpg images under 350Kb are accepted for upload";
  }
} else {
echo "Error: No file uploaded";
}
?>

 

What do i need to change to make this work for the php files. Waiting for the reply.

Thanks in advance.

Link to comment
Share on other sites

//&#1057;heck that we have a file
if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {
  //Check if the file is PHP file and it's size is less than 5Mb
  $filename = basename($_FILES['uploaded_file']['name']);
  $ext = substr($filename, strrpos($filename, '.') + 1);
  if (($ext == "swf") && 
    ($_FILES["uploaded_file"]["size"] < 5000000)) {
    //Determine the path to which we want to save this file
      $newname = dirname(__FILE__).'/upload/'.$filename;
      //Check if the file with the same name is already exists on the server
      if (!file_exists($newname)) {
        //Attempt to move the uploaded file to it's new place
        if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {
           echo "It's done! The file has been saved as: ".$newname;
        } else {
           echo "Error: A problem occurred during file upload!";
        }
      } else {
         echo "Error: File ".$_FILES["uploaded_file"]["name"]." already exists";
      }
  } else {
     echo "Error: Only .php files under 5Mb are accepted for upload";
  }
} else {
echo "Error: No file uploaded";
}
?>

Link to comment
Share on other sites

Its telling me that no file uploaded. I got that script from some random site. But when i run it on localhost. Its giving me the error that,

 

Error: No file uploaded

 

How should i write the code so that i can get a browse button & upload button for uploading a swf file.

btw thanks for looking to the code & taking the interest in solving the problem. :)

Link to comment
Share on other sites

Here's a basic example:

<h1 align="center">SWF Upload</h1>
<form enctype="multipart/form-data" method="post" action="">
<input type="hidden" name="MAX_FILE_SIZE" value="5000000" />
Choose SWF File To Upload: <input name="uploadedfile" type="file" id="uploadedfile" size="50" />
<input type="submit" name="submit" value="submit" />
</form>

<?php
if($_POST['submit'])
{

$target_path = "upload/";

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}

?>

Link to comment
Share on other sites

Donno what happened, but its giving me error

 

Parse error: syntax error, unexpected $end in C:\xampp\htdocs\upload.php on line 15

 

I tried running single file. But giving same error. I checked out the code, but there is no $end symbol in the code.

Then i made 2 files. First one is upload.html where i inserted html code & then upload.php where i've placed php code & made action="upload.php"

 

But still i'm getting the above error.

Thanks soo much. But still there is some problem. Waiting for your reply.  :(

Link to comment
Share on other sites

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.