Tag: file

GoDaddy’s Unlimited Upload File Size – Know The Facts

Recently there has been an argument on the GoDaddy Support Forums over the ability to upload files with no file size limit. You can view this thread here.

The thread began by jchasko who questioned a file size limit after receiving failures  upon uploading files around 4 gigabytes (GB).  GoDaddy Forums staff member christianh replied by referencing to an article on the GoDaddy Support website.

The article states that the upload file size limit is 1GB per file or 1GB total for all the files being uploaded at one time. Also, the upload size is limited by the space available on the user’s account. The article seems to explain the uploading limits clearly.

In another thread, viewable here, a few members requested cancellation of their accounts and refunds for not being given SFTP – a secure connection to their online storage folders.

One member, web_site_creat says:

Add me to the list. A secure connection is a must, there’s no good excuse not to have sftp or some sort of encryption without using the https://onlinefilefolder.com interface.

GoDaddy Forum staff member JasonP replied in the original thread that the upload file size limit is in fact 2GB – NOT 1GB as previously stated in the article provided and by christianh. About a month later, the same staff member, JasonP, then replies and says the upload limit is 1GB. This is after he said 1GB was wrong and that it should be a 2GB file size limit for uploads.

As if this was not enough confusion for the web hosting users, there was further complications with the GoDaddy’s features list. The Online Storage webpage from www.godaddy.com shows plans, pricing, comparisons between the GoDaddy features and other competitors, and more. On this page it states that with the GoDaddy services you get “Unlimited Sharing – Both for the number of files AND the file size.”

GoDaddy.com's Storage Features Comparison List

Following this statement is subtext in fine print that states “Subject to plan storage space limits” – which is suppose to clarify that file size limits are different for different accounts and their specifications. The problem is that this doesn’t quite simplify things or shine any light on the true details. In fact, upload file size limits are capped at 2GB according to most users’ experience at GoDaddy. That’s not even what the article that many staff members referred to says, as it claims the upload limit to be only 1GB total.

User bbakersmith comments about the upload file size limit and its intangibility:

Are you planning to update the information on https://www.godaddy.com/email/online-storage.aspx? You’ve obviously been made aware of this issue and yet it still states that the file size limit is “Unlimited” and that one of the features you offer is “Unlimited Sharing°. Both for the number of files AND the file size.”

The “°Subject to plan storage space limits” fine print doesn’t seem adequate as this implies that the max file size is the same as the max storage size.

All in all, the lesson here is that you must always read the fine print before making your final decision and ultimately, your purchase. File size limits can be an important point that must be covered when dealing with web hosting or server space because you may need access to large files such as: videos, downloads, programs, executable files, etc.

Always consider every possible need for your web hosting or server. Many times, companies will require you to purchase Virtual Private Servers (VPS) to acquire unlimited file sizes for upload and other undesired restrictions.

Thanks for reading.

Filed under: ArticlesTagged with: , , , , , , , , , , , , , ,

Simple File Hosting Script

I’ve made an easy to use file hosting script that is free for download.

It has some nice features such as:

  • Allowed file extensions.
  • File size limit.
  • Generated file names.
  • BBcode, IMG code, Url, etc.
  • Terms of Conditions

Generated file names on the server are created using the functions rand() and the md5() hash generator. Here is the code:

[code lang=”php”]

[/code]

The script also uses javascript to check for the Terms and Conditions checkbox being checked to make the submit button enabled.

I will be updating this script with more features, but this is meant to be a simple file hosting script. I will later include a download file page.

Here is what the upload form looks like:

filehostingscript

Check out the demo here!

Click here to download the script!

Filed under: ScriptsTagged with: , ,

PHP Get File Size of Remote File

Previously in a post I made for uploading a file from URL we wanted to include a file size check to make sure the file wasn’t too big before we upload it. Here I’ll show you how to get the remote file’s size and other information before doing other functions with it.

We’ll do this through a simple form. By default a form will encode all characters and convert spaces to “+” so we will leave the enctype undefined.

Then we just need the text input named “url” which I gave a default value “Enter URL Here…” and the Javascript-related attribute – onfocus. So when you focus on the text input it will change from the default value to blank.

Finally of course, we include the submit input named “submit” with the value “Submit.” We will use this value to check that the  form was submitted.

[codesyntax lang=”html4strict” title=”HTML Form”]
<form action=”getinfo.php” method=”post”>
<input type=”text” name=”url” size=”40″ value=”Enter URL Here…” onfocus=”if(this.value == ‘Enter URL Here…’) this.value = ”;” /> <input type=”submit” name=”submit” value=”Submit” />
</form>
[/codesyntax]

This HTML form will submit the entered url to getinfo.php.

We are going to the function fopen() to get the information we need from the remote file. There is one thing to be aware of using fopen() to retrieve this data. You need to be sure the fopen wrappers is enabled in your php.ini. This can not be changed using ini_set().

We are going to create a variable “contents” and add each line of the file to it as we read it. Then we will use the function mb_strlen() to get the file size of the variable. Normally we would use strlen(), however that will only read one character as one byte. That doesn’t really give you the most accurate reading if you have special characters in the file which are more than one byte.

By default the function fgets() reads each line of a file 1024 bytes at a time. The function runs until either the specified length is reached (1024 bytes) or to the end of the file. It is more resource efficient to specify a read length:

“Until PHP 4.3.0, omitting it would assume 1024 as the line length. If the majority of the lines in the file are all larger than 8KB, it is more resource efficient for your script to specify the maximum line length.”php.net

getinfo.php

[codesyntax lang=”php” title=”getinfo.php Source Code”]
<?php
// getinfo.php

if($_POST[“submit”]){
// Form is submitted.

// Check the fopen wrapper settings in php.ini
if (ini_get(“allow_url_fopen”) == 1) {

// Open the file.
$file = fopen(trim($_POST[“url”]), “r”);

if($file){
// We got the file.

$contents = “”;
while($line = fgets($file,1024)){
// Write each line to the string contents a kilobyte at a time.
$contents .= $line;
}

$filesize = mb_strlen($contents,”8bit”);
$kb = $filesize / 1024; // Returns the file size in kilobytes
echo “<strong>File Size</strong>:  “.$filesize.” bytes or “.$kb.” kilobytes.”;

} else {

echo “Remote file not found.”;

}

} else {

echo “Fopen wrappers not enabled.”;

}

}

?>
[/codesyntax]

The page will display the file size in bytes and kilobytes, as so:
File Size: 1024 bytes or 1 kilobytes.

Filed under: PHP, Tutorials, Web ProgrammingTagged with: , , ,

PHP Upload file from URL

Let’s say you have a form on a page with the input for URL to a file so you can upload it to your server. You can do this using PHP functions.

Here is an example of a form to upload:

[code lang=”html”]

Enter URL:

[/code]

Now on upload.php we need to have PHP run an upload of the file based on the entered URL. Here is how it will look.

The form above submitted two variables, the url text, and the submit button (value “submit”). So when we start the PHP code, we check it was submitted with the submit button.

We trim the url submitted through the form using the function trim() for the url to be accessed then create a filename using the function basename(). We then check that the url exists after having these functions applied to it. This is what we are going to submit to upload.

$file = Opening the url submitted with read-only permissions. This is defined with the “rb.”

[code lang=”php”]
$file = fopen($url,”rb”);
[/code]

Once we have opened the file we create a random number. This is going to be added to the file’s name when we upload it so that no two files have the same name. This is done very simply with the function rand(). Simply set the minimum and maximum for random numbers.

$newfile = Open the new file we are creating on our server. This actually creates the file on the server in the folder $directory with the random number ($rand) and the file’s name ($filename). This is done with writing permissions so that we can write the data from the url file to this one.

[code lang=”php”]
$rand = rand(1000,9999); // random number 4 digits long
$filename = $rand . basename($url); // places random number in front of the url’s base name
$newfile = fopen($directory . $filename, “wb”);
[/code]

If this new file can be created, we start writing the data to the file. To do this we use the function feof(). So if the new file exists now, while we haven’t reached the end of the url file, we write this content to the one on our server. This sounds a little confusing but it is quite easy.

Code:

[code lang=”php”]
if($newfile){
while(!feof($file)){

// Write the url file to the directory.
fwrite($newfile,fread($file,1024 * 8),1024 * 8);
}

}
[/code]

This script basically says write the data of the url file up until we reach 8kb, to the new file we created on the server. You can adjust the maximum size in kb by changing the “8” to whatever you wish. Once it reaches the end of the file, it will stop writing.

Now let’s say we want to check for filetypes. No one wants people uploading unsafe filetypes to their server. This is a serious problem if you do not check the filetypes being uploaded. So once we establish that the file exists through the URL we are going to check its extension to match ones we allow.

$valid_exts = An array of the valid extensions we allow the user to upload. (i.e. image files).

[code lang=”php”]
$valid_exts = array(“jpg”,”jpeg”,”gif”,”png”);
[/code]

$ext = We find the extension of the file by using the function explode(). This function splits the url into an array based on a seperator, in this case the seperator is a period “.” to find the trailing extension. We then set this to all lowercase because that is what our valid extensions are in. Also, we use the end() function to this array because it is possible the url has more than one period in it. We want to make sure we get JUST the extension on the end.

[code lang=”php”]
$ext = end(explode(“.”,strtolower(basename($url))));
[/code]

Here is the complete code:

Upload.php

[codesyntax lang=”php” title=”upload.php PHP Source Code”]<?php
// UPLOAD.PHP
if($_POST[“submit”]){
$url = trim($_POST[“url”]);
if($url){
$file = fopen($url,”rb”);
if($file){
$directory = “./downloads/”; // Directory to upload files to.
$valid_exts = array(“jpg”,”jpeg”,”gif”,”png”); // default image only extensions
$ext = end(explode(“.”,strtolower(basename($url))));
if(in_array($ext,$valid_exts)){
$rand = rand(1000,9999);
$filename = $rand . basename($url);
$newfile = fopen($directory . $filename, “wb”); // creating new file on local server
if($newfile){
while(!feof($file)){
// Write the url file to the directory.
fwrite($newfile,fread($file,1024 * 8),1024 * 8); // write the file to the new directory at a rate of 8kb/sec. until we reach the end.
}
echo ‘File uploaded successfully! You can access the file here:’.”\n”;
echo ”.$directory.$filename.”;
} else { echo ‘Could not establish new file (‘.$directory.$filename.’) on local server. Be sure to CHMOD your directory to 777.’; }
} else { echo ‘Invalid file type. Please try another file.’; }
} else { echo ‘Could not locate the file: ‘.$url.”; }
} else { echo ‘Invalid URL entered. Please try again.’; }
}
?>

[/codesyntax]

When the form is submitted, PHP uploads the file to the directory – $directory – which is set to “./downloads/” by default. The function !feof() reads as – before reaching the end of a file. So while it hasn’t reached the end, write to $directory. Once the function returns false (when we have reached the end of the file) it will stop. The path to the file is given as “$directory.$filename.”

I have made a script for uploading multiple files from a URL or your computer’s HDD viewable here:

https://bgallz.dev/1345/php-upload-multiple-files-url/

Enjoy!

Filed under: PHP, Tutorials, Web ProgrammingTagged with: , , , , ,

Uploading Files with PHP

With many forms you may want to include some sort of upload of a file. There are many functions for files in PHP that you can use to do this.

Some things you may want to consider when uploading a file to your server:

  • File extension – what type of file is being uploaded.
  • File size – How big is the file, should the be a limit?
  • What to do on a successful upload.

Here is a basic form uploading to the file “upload.php”.

[code lang=”html”]


[/code]

Now on upload.php we need to have code that reacts to this form being submitted, other wise nothing will happen obviously.

[code lang=”php”][/code]

That would be our code for upload.php. When the form is submitted it will execute that code and perform the upload as long as it passes the tests.

You  can specify any directory, extensions, filesize limit you want of course. Enjoy.

Filed under: Scripts, TutorialsTagged with: , ,