Novahq.net Forum

Novahq.net Forum (https://novahq.net/forum/index.php)
-   phphq.Net Forums (https://novahq.net/forum/forumdisplay.php?f=277)
-   -   phUploader question (https://novahq.net/forum/showthread.php?t=46930)

Shone 10-14-2012 06:59 PM

phUploader question
 
How can you make this script not upload anything if any error occurs ?

Thanks

Scott 10-22-2012 01:31 PM

If there is an error, nothing will be uploaded. However, the file can't be checked to make sure it's the right type until after it's been uploaded. That's just the way PHP works.

Shone 10-25-2012 04:19 PM

Quote:

Originally Posted by Scott (Post 379926)
If there is an error, nothing will be uploaded. However, the file can't be checked to make sure it's the right type until after it's been uploaded. That's just the way PHP works.

Lets say max upload size of one file is 512kb. If I try to upload one file that is 200kb in size and one that is 1mb in size, first one will be uploaded and second one will fail because of error. How can I prevent that any of other files get uploaded when some error occurs. In this example I want first file not to get uploaded because I had one error with some other file upload. I was trying to make a condition :
if ( $error > 0 ) {
display some error msg...
}
but it is not working, if you try you will see why.

Scott 10-26-2012 08:39 AM

That would be a pretty big adjustment to the script.. you're probably better off to just delete files that were uploaded, if any in the group had an error... Try doing the below adjustments..

On line 249, after
PHP Code:

$success.="<b>URL:</b> <a href=\"".$full_url.$file_name[$i].".".$file_ext[$i]."\" target=\"_blank\">".$full_url.$file_name[$i].".".$file_ext[$i]."</a><br /><br />"

Add this
PHP Code:

$uploaded[]=$folder.$file_name[$i].".".$file_ext[$i]; 

Then on line 261, after this
PHP Code:

// Else Total Size 

Add this
PHP Code:

If($error) {
    
$success="";
    
$error.="<b>FAILED:</b> No files uploaded<br />";
    If(
is_array($uploaded) AND !empty($uploaded)) {
        For(
$i=0$i <= count($uploaded-1); $i++) {
            @
unlink($uploaded[$i]);
        }
    }



I did not test it, but it should work. You could also put the success files into an array, and if you get any errors by the end, loop through that array only to delete any uploaded files.

Shone 10-28-2012 03:39 PM

Thank you, that worked...


All times are GMT -5. The time now is 02:24 AM.

Powered by vBulletin®