Go Back   Novahq.net Forum > phphq.Net > phphq.Net Forums

Reply
 
Thread Tools Search this Thread Display Modes
  #1  
Old 10-14-2012, 06:59 PM
Shone is offline Shone
Registered User

Join Date: Sep 2012
Posts: 4

phUploader question

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

Thanks
Reply With Quote
  #2  
Old 10-22-2012, 01:31 PM
Scott is offline Scott
Scott's Avatar
AKA. Panther

Join Date: Sep 2001
Location: Minneapolis, MN
Posts: 10,919

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.
__________________

04' Dodge SRT-4, Mopar Stage 3, 406whp/436wtq
Reply With Quote
  #3  
Old 10-25-2012, 04:19 PM
Shone is offline Shone
Registered User

Join Date: Sep 2012
Posts: 4

Quote:
Originally Posted by Scott View Post
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.
Reply With Quote
  #4  
Old 10-26-2012, 08:39 AM
Scott is offline Scott
Scott's Avatar
AKA. Panther

Join Date: Sep 2001
Location: Minneapolis, MN
Posts: 10,919

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.
__________________

04' Dodge SRT-4, Mopar Stage 3, 406whp/436wtq
Reply With Quote
  #5  
Old 10-28-2012, 03:39 PM
Shone is offline Shone
Registered User

Join Date: Sep 2012
Posts: 4

Thank you, that worked...
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 12:28 PM.




Powered by vBulletin®