Jump to content

Recommended Posts

Hi all,

 

I have a question. I have written a couple of scripts to upload files. They are only the basic version and I know they need a lot before they go into production but I'm just trying to get them to work.

 

My issue is that these scripts work on all three servers I have access to but not on the guy's who I am writing them for. I have tested them on fasthosts, 1and1 and bargainhosts servers and this all works perfectly. The issue is that on mediatemple the script won't do the actual copy part.

We don't get a specific error.

 

I'm fairly certain that the issue lie in the php config but I am no expert with this at all.

 

Does anyone have any idea's?

 

My code for examples

 

Version 1

<?php
############################
# Lets do some config
# Specify the max size in KB i.e. 1000 bytes
# So 1000 = 1MB and 1000000 = 1GB
$maxSize = "1000";
# Now we need to tell the program where to put the file it uploads
$location = "/path to file/";
###########################
#ÊDO NOT MESS BELOW THIS LINE #









if(isset($_POST['Submit'])){

define ("MAX_SIZE",$maxSize);
$errors=0;

	$image=$_FILES['image']['name'];

	if($image){
            $filename = stripslashes($_FILES['image']['name']);
            $size=filesize($_FILES['image']['tmp_name']);

                if ($size > MAX_SIZE*1024)
                {
                        echo 'That file is too big!';
                        $errors=1;
                }

        $newname=$location.$filename;

        $copied = copy($_FILES['image']['tmp_name'], $newname);
        
        if (!$copied){
                echo 'It didnt work!';
                $errors=1;
        }
        
        }
} else {
showForm();
}


if(isset($_POST['Submit']) && !$errors){
    echo "File Uploaded Successfully!";
}

function showForm(){
?>
<form method="post" enctype="multipart/form-data"  action="">
<input type="file" name="image">
<input name="Submit" type="submit" value="Upload">
</form>
<?
}
?>


 

Version 2

<?php
############################
# Lets do some config
# Specify the max size in bytes i.e. 1000 bytes
# So 1000 = 1KB and 1000000 = 1MB and 1000000000 = 1GB
$maxSize = "1000000";
# Now we need to tell the program where to put the file it uploads
$location = "/path to files/";
###########################
#ÊDO NOT MESS BELOW THIS LINE #









if(isset($_POST['sub'])){


        $target_path = $location . basename( $_FILES['filename']['name']);
        
        if(basename( $_FILES['filename']['size']) > $maxSize){
                $errors =1;
                echo "The file is too big at " . basename( $_FILES['filename']['size']) . " bytes. We are restricted to " . $maxSize . " bytes";
        }
        
        if(isset($_POST['sub']) && !$errors){
                if(move_uploaded_file($_FILES['filename']['tmp_name'], $target_path)) {
                        echo "The file ".  basename( $_FILES['filename']['name']). " has been uploaded. ";
                        echo "The file was " . basename( $_FILES['filename']['size']). " bytes. <br/>";
                        echo "Fancy another go?<br/>";
                        showForm();
                        
                } else {
                        echo "There was an error uploading the file, please try again!<br/>";
                        showForm();
                }
        } else {
                echo " Sorry, it's a no go";
                showForm();
        }

        
} else {
showForm();
}




function showForm(){
?>
<form enctype="multipart/form-data" action="" method="post">
        <input type="hidden" name="sub" value="1" />
        Choose a file to upload <input type="file" name="filename"/>
        <input type="submit" value="Upload" />
        </form>

<?
}
?>


Link to comment
https://forums.phpfreaks.com/topic/189986-problem-uploading-files/
Share on other sites

Add the following lines of debugging code immediately after the first opening <?php tag and tell us what is displays after the form is submitted -

 

ini_set("display_startup_errors", "1");
ini_set("display_errors", "1");
error_reporting(E_ALL);
echo "<pre>";
echo "POST:";
print_r($_POST);
echo "FILES:";
print_r($_FILES);
echo "</pre>";

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.