FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


upload form





Relentless
This is driving me nuts been at it for hours. its now 3:30am and i'm really tiered. so please mind the spelling.

I want the ability for people to upload tempoary files to my server.

So I went browesing (as you do) and came across 3 websites. I followed every instruction and still it doesn't work. I'm not very good with PHP so I will show you what I was given.

The form:
Code:
<form enctype="multipart/form-data" action="getfile.php" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="2097152" />
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>

It didn't say if this had to be saved as a .php or .htm so i saved it as both and niether worked.

But of course it will not work without this next bit (which keeps coming up wrong)
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";
}
?>

This I saved as getfile.php now that is one of them here is the other
<html>
<head>
<title>Process Uploaded File</title>
</head>
<body>
Code:
<?php

if ( move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'],
       "../uploads/{$_FILES['uploadFile'] ['name']}")  )
      {  print '<p> The file has been successfully uploaded </p>';
       }
else
      {
        switch ($_FILES['uploadFile'] ['error'])
         {  case 1:
                   print '<p> The file is bigger than this PHP installation allows</p>';
                   break;
            case 2:
                   print '<p> The file is bigger than this form allows</p>';
                   break;
            case 3:
                   print '<p> Only part of the file was uploaded</p>';
                   break;
            case 4:
                   print '<p> No file was uploaded</p>';
                   break;
         }
       }

?>
</body>
</html>

I also saved this as getfile.php

Niether works.

Can anybody help me Very Happy
Or make me one? I will pay 50 Frih$ or more if anybody can make me a working .php FILE/DOCUMENT and i want the files to be save in a folder called "uploads" in the same directory.

Thanks Daniel.
sonam
Look here:
http://www.frihost.com/users/sonam/blog/vp-82594.html

Sonam
lukand
Relentless wrote:
This is driving me nuts been at it for hours. its now 3:30am and i'm really tiered. so please mind the spelling.

I want the ability for people to upload tempoary files to my server.

So I went browesing (as you do) and came across 3 websites. I followed every instruction and still it doesn't work. I'm not very good with PHP so I will show you what I was given.

The form:
Code:
<form enctype="multipart/form-data" action="getfile.php" method="POST">
    <input type="hidden" name="MAX_FILE_SIZE" value="2097152" />
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>

It didn't say if this had to be saved as a .php or .htm so i saved it as both and niether worked.

But of course it will not work without this next bit (which keeps coming up wrong)
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";
}
?>

This I saved as getfile.php now that is one of them here is the other
<html>
<head>
<title>Process Uploaded File</title>
</head>
<body>
Code:
<?php

if ( move_uploaded_file ($_FILES['uploadFile'] ['tmp_name'],
       "../uploads/{$_FILES['uploadFile'] ['name']}")  )
      {  print '<p> The file has been successfully uploaded </p>';
       }
else
      {
        switch ($_FILES['uploadFile'] ['error'])
         {  case 1:
                   print '<p> The file is bigger than this PHP installation allows</p>';
                   break;
            case 2:
                   print '<p> The file is bigger than this form allows</p>';
                   break;
            case 3:
                   print '<p> Only part of the file was uploaded</p>';
                   break;
            case 4:
                   print '<p> No file was uploaded</p>';
                   break;
         }
       }

?>
</body>
</html>

I also saved this as getfile.php

Niether works.

Can anybody help me Very Happy
Or make me one? I will pay 50 Frih$ or more if anybody can make me a working .php FILE/DOCUMENT and i want the files to be save in a folder called "uploads" in the same directory.

Thanks Daniel.



This form on my localhost's pages don't work, any errors while I upload file
Relentless
Don't Worry guys i done it. Found somthing on the internet...

And it works fab.

Cheers guys.

If anybody wants the form I got then i will send it to you.

Dan
Related topics
File upload with PHP, Build an upload database for your site
Rad Upload Plus v1.22
Which Firefox Extentions?
ImageShack's Tools
ImageShack's Tools
cgi-bin help
Help with upload form script! [RESOLVED]
Funny Pictures!
Zip archive extraction with PHP
Script for Upload Form
How to build simple PHP upload form
How to build PHP mail form with Spam protection
I need an upload form
Bulk file upload form a web browser?
Reply to topic    Frihost Forum Index -> Scripting -> Php and MySQL

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.