Jump to content

Upload Script lying to me


phpstuck

Recommended Posts

Simple stuff to some I know, but this is my first attempt as I have never needed it before. Before anyone tells me this is insecure I know, I have removed all checks and restrictions to make this as simple as possible for me to break down, I will add security as soon as I can figure out why it says successful yet puts nothing in the server folder.

I created a folder named "uploads" on the server and changed the permissions to 777

Then I use this HTML to gather the file for upload
uploadtest.html
[code]
<form method="POST" enctype="multipart/form-data" action="me.php">
  <p>
  Select a file:
  <input type="file" name="upfile"><br>
  <br>
  <br>
  <br>
  <input type="submit" value="Upload"></p>
</form>
[/code]

Then I created this to process the posted data
me.php
[code]
<?php
$uploaddir = "uploads";
$uploadfile = $uploaddir . $_FILES['upfile']['name'];
if (move_uploaded_file($_FILES['upfile']['tmp_name'],
$uploadfile)) {
  print("File upload was successful");
  } else {
    print("File upload failed");
  }

?>
[/code]

When I run the script live on my server I get the "File upload was successful" message, but when I check the folder on the sever nothing was actually uploaded.

Any help would be really appriciated :-)



Link to comment
Share on other sites

Ok that problem is fixed by changing the code as follows, uploads work fine.

[code]<?php
error_reporting(E_ALL & ~E_NOTICE);
$uploaddir = "uploads/";
$filename = trim($_FILES['upfile']['name']);
$filename = substr($filename, -15);
$filename = ereg_replace(" ", "",$filename);
if((ereg(".jpg", $filename)) || (ereg(".gif", $filename))) {
    $uploadfile = $uploaddir . $filename;
    if (move_uploaded_file($_FILES['upfile']['tmp_name'],
    $uploadfile)) {
      chmod($uploadfile, 0644);
      print("File upload was successful");
      } else {
        print("File upload failed");
      }
      } else {
        print("Only images in .gif or .jpg extentions are allowed, upload failed!");
        }
?>
[/code]

But I sure would like to know how to change the filename after submission to something unique so I don't ever end up with two files of the same name with one overwritting the other :-)
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.