Jump to content

Help with Upload script


1219

Recommended Posts

I want to be able to upload at least a maximum of 50MB here is my PHP code:

 

 

        <?php

        $MAX_SIZE = 90000000;                     

        $FILE_EXTS  = array('.jpg','.gif','.png','.psd','.eps','.ai','.exe','.zip','.tar','.sit','.txt','.doc','.pdf','.rtf','.ste','.stc');

        $DELETABLE  = true;                             

        $site_name = $_SERVER['HTTP_HOST'];

        $url_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);

        $url_this =  "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];

        $upload_dir = "1/";

        $upload_url = $url_dir."/1/";

        $message ="";

        if (!is_dir("1/")) {

        if (!mkdir($upload_dir))

        die ("upload_files directory doesn't exist and creation failed");

        if (!chmod($upload_dir,0777))

        die ("change permission to 777 failed.");

        }

        if ($_REQUEST[del] && $DELETABLE)  {

        $resource = fopen("../logs/upload.txt","a");

        fwrite($resource,gmdate("m.d.Y h:i A \E\S\T", time() -14500)." $_SERVER[REMOTE_ADDR] - Delete "."$_REQUEST[del]\n");

        fclose($resource);

        if (strpos($_REQUEST[del],"/.")>0);

        else if (strpos($_REQUEST[del],$upload_dir) === true);

        else if (substr($_REQUEST[del],0,2)==$upload_dir) {

        unlink($_REQUEST[del]);

        print "<script>window.location.href='$url_this?message=Deleted successfully.'</script>";

        }

        }

        else if ($_FILES['UserFile']) {

        $resource = fopen("../logs/upload.txt","a");

        fwrite($resource,gmdate("m.d.Y h:i A \E\S\T", time() -14500)." $_SERVER[REMOTE_ADDR] - Upload " .$_FILES['UserFile']['name']."\n");

        fclose($resource);

        $file_type = $_FILES['UserFile']['type'];

        $file_name = $_FILES['UserFile']['name'];

        $file_ext = strtolower(substr($file_name,strrpos($file_name,".")));

        if ( $_FILES['UserFile']['size'] > $MAX_SIZE)

        $message = "The file size is over 50MB.";

        else if (!in_array($file_ext, $FILE_EXTS))

        $message = "Sorry, this file is not allowed to be uploaded.";

        else

        $message = do_upload($upload_dir, $upload_url);

        print "<script>window.location.href='$url_this?message=$message'</script>";

        }

        else if (!$_FILES['UserFile']);

        else

        $message = "Invalid file specified.";

        $handle=opendir($upload_dir);

        $filelist = "";

        while ($file = readdir($handle)) {

        if(!is_dir($file) && !is_link($file)) {

        $filelist .= "<li><a href='$upload_dir$file'>".$file."</a>";

        if ($DELETABLE)

        $filelist .= " - <a href='?del=$upload_dir".urlencode($file)."' title='Delete'>x</a></li>";

        }

        }

        function do_upload($upload_dir, $upload_url) {

        $temp_name = $_FILES['UserFile']['tmp_name'];

        $file_name = $_FILES['UserFile']['name'];

        $file_name = str_replace("\\","",$file_name);

        $file_name = str_replace("'","",$file_name);

        $file_path = $upload_dir.$file_name;

        if ( $file_name =="") {

        $message = "Invalid file name specified.";

        return $message;

        }

        $result  =  move_uploaded_file($temp_name, $file_path);

        if (!chmod($file_path,0777))

        $message = "Change permission to 777 failed.";

        else

        $message = ($result)?"Uploaded successfully." :"Something is wrong with uploading a file.";

        return $message;

        }

        ?>

 

 

 

 

This is my PHP.INI file:

 

 

register_globals = Off

safe_mode = On

max_execution_time = 1600

memory_limit = 100M

post_max_size = 100M

upload_max_filesize = 100M

 

 

 

 

 

Any clues about why it will upload less than 2MB but nothing more?

 

Link to comment
https://forums.phpfreaks.com/topic/46739-help-with-upload-script/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.