Jump to content

HELP modify a novice's short code!!


jettjordan23

Recommended Posts

Hello all!  I have a very short piece of code that I was hoping that someone here could help me modify.  Essentially, I am attempting to code through an html form and a server side script that will allow a user to my website to upload a file to my server.  As of now, the code works, but for the last 8 hours, I have been trying to modify it to no luck.  What I would like the sever side script to do is to

 

1. Give each file uploaded a unique filename so that they do not write over other files with the same name.  I was thinking about adding a timestamp to the end of each name before it is saved..

2. Restrict the type of files uploaded to .pdfs and Microsoft word documents. 

 

Below, I have pasted both my form and my php.  Any help would be greatly appreciated.  I am a terrible programmer and have literally been up for 8 straight hours trying to get this to work, but too no avail.  Thank you so much for all of your help!

 

FORM

 

<form enctype="multipart/form-data" action="fileupload2.php" method="POST">
    <!-- MAX_FILE_SIZE must precede the file input field -->
    <input type="hidden" name="MAX_FILE_SIZE" value="30000" />
    <!-- Name of input element determines name in $_FILES array -->
    Send this file: <input name="userfile" type="file" />
    <input type="submit" value="Send File" />
</form>

 

 

SERVER SIDED SCRIPT

<?php

echo 'Upload result:<br>'; // At least one symbol should be sent to response!!!

$uploaddir = dirname($_SERVER['SCRIPT_FILENAME'])."/../";

echo '<pre>';
if(count($_FILES) > 0)
{
$arrfile = pos($_FILES);
$uploadfile = $uploaddir . basename($arrfile['name']);

if (move_uploaded_file($arrfile['tmp_name'], $uploadfile))
   echo "File is valid, and was successfully uploaded.\n";
}
else
echo 'No files sent. Script is OK!'; //Say to Flash that script exists and can receive files

echo 'Here is some more debugging info:';
print_r($_FILES);

echo "</pre>";

?>

 

EDITED BY WILDTEEN88: Please use code tags (


)

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.