Jump to content

[SOLVED] Upload script modification


lindm

Recommended Posts

I am trying to create an upload script that performs the following:

 

1. Uploads to the file to the same directory as the upload.php script (right now it uploads to root it seems..)

2. Renames the file to xxx.txt (no function for this yet)

3. If xxx.txt exists it replaces this one (no function for this yet)

4. Limits import by file extensions (.se and .sie) (no function for this yet)

 

Found some beginning code on the internet and here is my result so far:

 

<?php 
$target = "/"; 
$target = $target . basename( $_FILES['uploaded']['name']) ; 
$ok=1; 

//This is our size condition 
if ($uploaded_size > 100000) 
{ 
echo "Your file is too large.<br>"; 
$ok=0; 
} 


//Here we check that $ok was not set to 0 by an error 
if ($ok==0) 
{ 
Echo "Sorry your file was not uploaded"; 
} 

//If everything is ok we try to upload it 
else 
{ 
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
{ 
echo "The file ".basename( $_FILES['uploadedfile']['name']). " has been uploaded"; 
} 
else 
{ 
echo "Sorry, there was a problem uploading your file."; 
} 
} 
?>

 

Any help to complete much appreciated.

 

 

 

Link to comment
Share on other sites

Hello again,

 

What I am now trying is modifying my existing import script. I have (with help of course) created two functions that import data from an external file. What I am trying is to make the $contents (below) read the file that a user specifies in a separate form on a separate html page. In other words:

 

1. User is on form.html. User browses local drive and selects a file.

2. Form.html is submitted to import.php which contains the script below.

 

$contents = file('file.txt');

foreach($contents as $line_value)
{

list($cat, $int, $id, $num) = explode("\t", $line_value);

    $cat = str_replace('#', '', $cat);

    $number[$cat][$int][$id] = trim($num);
}
//SIE FÖR ATT SUMMERA
function calculate_range($cat, $bool, $range_min, $range_max)
{
    global $number;

    $total = 0;

    for($i = $range_min; $i <= $range_max; $i++)
    {
        if(isset($number[$cat][$bool][$i]))
        {
            $total += $number[$cat][$bool][$i];
        }
    }

    return $total;
}

 

 

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.