Jorm
Jorm

Reputation:

move_uploaded_file help

<?php

if (count($_POST)) {

$userfile = $_FILES['userfile']['name'];
$file_size = $_FILES['userfile']['size'];
$file_temp = $_FILES['userfile']['tmp_name'];
$path = 'uploads/';

$randomizer = rand(0000, 9999);
$file_name = $randomizer.$userfile;

    if($file_size > 25600) {
        echo 'FILE SIZE TO LARGE<BR />';
        exit();
    }


   if (move_uploaded_file($file_temp, $path.$file_name)) {
        echo '<h3>Upload Successful!</h3>';
    } else {
        echo '<h3>ERROR</h3>';
    }

 }
?>


<form enctype="multipart/form-data" method="post">
Upload File: <input name="userfile" type="file" /> <br />
<input type="submit" value="Upload File" />
</form>

I do have a folder named uploads in my root but still this wont work, i dont even get the error. Getting tired..Whats wrong?

Upvotes: 0

Views: 345

Answers (1)

Matthew Iselin
Matthew Iselin

Reputation: 10670

You might be better off doing something like:

if (isset($_FILES['userfile'))

In your current code, do you know whether the lines within the "if (count($_POST))" block actually execute? The first thing I would've done is shoved a print_r call (or even just echoed some text) into both the if block and created an else block with an echo statement.

It just means you know what it's trying to do, and where it's failing, rather than trying to make guesses at it.

Upvotes: 1

Related Questions