CodeCanyon

Secure File Upload Class

  • Has been a member for 3-4 years
  • Sold between 100 and 1 000 dollars
  • Bought between 100 and 499 items
  • United Kingdom
Slappit says

Hi, i have a few questions if you could please answer them i would be thankful.

1. i am developing this website that allows upload of mp4 and ogv, so is it possible to add 2 uploads.

Would it be as simple as:

$mp4_upload = new upload($_POST[‘mp4’]);
$ogv_upload = new upload($_POST[‘ogv’]);

2. how easy is it to add to table within database and to upload folder?

3. does this extension check to stop dangerous uploads?

4. does this have the ability to either add random numbers after each upload or change the upload name so that if a uploaded file has the same name as others it does not matter.

Thanks

5 months ago
Author
betterphp betterphp replied

1. that should be possible yea, you would need to create two instances of the upload class.

2. Quite easy, you would just need to run the INSERT query where the success message is normally shown in the examples.

3. Pretty much yes, you should also use the mime whitelist too to make sure that the file types match the extension they have.

4. Nope, sorry :(

5 months ago
  • Has been a member for 3-4 years
  • Sold between 100 and 1 000 dollars
  • Bought between 100 and 499 items
  • United Kingdom
Slappit says
Purchased

Hi

i purchased the item anyway and i have a few errors when a file has not been uploaded.

Here are the errors:

Notice: Undefined index: video in C:\wamp\www\applications\controllers\upload-class.php on line 42
Notice: Undefined index: video in C:\wamp\www\applications\controllers\upload-class.php on line 43
Notice: Undefined index: video in C:\wamp\www\applications\controllers\upload-class.php on line 47
Notice: Undefined index: video in C:\wamp\www\applications\controllers\upload-class.php on line 48
Notice: Undefined index: video in C:\wamp\www\applications\controllers\upload-class.php on line 49

The setup i have put is as follows:

$video_mp4 = new secure_upload('video'); $video_mp4->set_type_whitelist(array('video')); $video_mp4->set_extension_blacklist(array('php', 'phtml', 'php3', 'php4', 'php5', 'js', 'shtml', 'pl', 'py', 'html', 'exe', 'htm', 'tpl', 'asp', 'xml', 'ph3', 'ph4', 'ph5', 'ph3', 'mov', 'mpeg', 'avi', 'mp3', 'txt', 'gif', 'png', 'jpg', 'jpeg','ogv')); $video_mp4->set_extension_whitelist(array('mp4')); $video_mp4->save_to('/video/main/' . $video_mp4->name);

Could you please help me solve this issue.

Instead of getting errors it should just give a error report, file not uploaded.

Thanks

5 months ago
Author
betterphp betterphp replied

Does the key in the $_FILES array defiantly exist ? So you have a form that looks somethign like this

<form enctype="multipart/form-data" method="post" action="">
    <div>
        <input name="video" type="file" />
        <input value="Upload" type="submit" />
    </div>
</form>
5 months ago
  • Has been a member for 3-4 years
  • Sold between 100 and 1 000 dollars
  • Bought between 100 and 499 items
  • United Kingdom
Slappit says
Purchased

ok i have put my own error report in basically saying:
if($video_ogv[‘size’] 0){
tell no file was uploaded
} else {
do class
}

That has sorted that even the the class should have taken care of that anyway!

Now the other issue is when files are being uploaded its not uploading and its not giving an error to say otherwise, here is how i have laid things out!:

if($video_mp4['size'] 0){
$errors[] = “No MP4 Video Was Inserted”;
} else {
$video_mp4 = new secure_upload(‘video’);
$video_mp4->set_type_whitelist(array(‘video’));
$video_mp4->set_extension_whitelist(array(‘mp4’));
$video_mp4->save_to(’/video/main/’ . $video_mp4->name);
if ($video_mp4->error > 0){
$errors[] = “Your mp4: ” . $video_mp4->get_error_constant_name();
}

This is the only section where anything can go wrong as its the only section with any coding really!

Thanks

5 months ago
Author
betterphp betterphp replied

Could you email me a zip of all of the files ? It’s pretty hard to tell what;s going on in these comments ;)

5 months ago
  • Has been a member for 3-4 years
  • Sold between 100 and 1 000 dollars
  • Bought between 100 and 499 items
  • United Kingdom
Slappit says
Purchased

ive posted on your forum, as can get a little more in depth there.

I like your tutorial section by the way, the api has helped me alot :)

Thanks

5 months ago
  • Has been a member for 3-4 years
  • Sold between 100 and 1 000 dollars
  • Bought between 100 and 499 items
  • United Kingdom
Slappit says
Purchased

how would i be able to implement random numbers appending on the end so the file is unique each time, the reason i say is because if you have 2 instances and the second one fails, when you re-submit the file exists because the upload has been executed already. So this is not ideal for multi-upload on 1 page.

5 months ago
Author
betterphp betterphp replied

You would have to modify the $_FILES array before creating the upload object, something like

$_FILES['something']['name'] = rand() . $_FILES['something']['name'];

A little big of a dodgy method but it should work.

5 months ago
  • Has been a member for 3-4 years
  • Sold between 100 and 1 000 dollars
  • Bought between 100 and 499 items
  • United Kingdom
Slappit says
Purchased
i did it a little differently

I changed line 42 of the class to this
$this->name = rand(1,999999) . $_FILES[$key]['name'];
I dont think there is any security issues from this but its your class so what do you think?
5 months ago
Author
betterphp betterphp replied

Yeah that is a much better way to do it, I only suggested the first method to stop you having to edit the class directly ;)

5 months ago
  • Has been a member for 1-2 years
  • Bought between 100 and 499 items
  • Germany
michaeldiminakis says
Purchased

Hi i have buy this great PHP Class. Thats all ok but i have a question. Is it possible to give the User a progress or a popup like “your UPload is in progess” ???

Any ideas :-)

2 months ago
Author
betterphp betterphp replied

It is possible, but it’s not somethign that this class handles. You would need to us ea bit of JavaScript.

2 months ago
Purchased
Default-user michaeldiminakis replied

Hi thanks for this answer.

I make a jquery post call to a ajaxloader.php where includes your class.

But i need to become the $_FILES variable to the ajaxloader.php with jquery. How o make this. Just only transmit the value of the input file name dont work

thanks

1 month ago
Author
betterphp betterphp replied

Sorry I only know how to do it with pure JavaScript :(

1 month ago
by
by
by
by
by