Conditions | 106 |
Paths | 1651 |
Total Lines | 621 |
Lines | 162 |
Ratio | 26.09 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | #!/usr/bin/env php |
||
296 | function ftp_Run() { |
||
297 | global $FTP, $ARCurrent, $ARBeenHere; |
||
298 | |||
299 | while (ftp_FetchCMD($cmd, $args)) { |
||
300 | $ARBeenHere=array(); |
||
301 | $ARCurrent->arLoginSilent = 0; |
||
302 | $ARCurrent->ftp_error = ""; |
||
303 | |||
304 | if ($last_cmd != 'REST') { |
||
|
|||
305 | $FTP->resume = 0; |
||
306 | } |
||
307 | switch ($cmd) { |
||
308 | case 'MDTM': |
||
309 | $path = $args; |
||
310 | ftp_TranslatePath($path, $listMode); |
||
311 | switch ($listMode) { |
||
312 | View Code Duplication | case 'templates': |
|
313 | ftp_TranslateTemplate($path, $template); |
||
314 | |||
315 | $result = current( |
||
316 | $FTP->store->call("ftp.template.exists.phtml", |
||
317 | array("arRequestedTemplate" => $template), |
||
318 | $FTP->store->get($path))); |
||
319 | $file_date = $result["date"]; |
||
320 | |||
321 | if ($file_date) { |
||
322 | ftp_Tell(213, date("YmdHis", $file_date)); |
||
323 | } else { |
||
324 | ftp_Tell(550, "No such file or directory"); |
||
325 | } |
||
326 | break; |
||
327 | default: |
||
328 | if ($FTP->store->exists($path)) { |
||
329 | $file_date = time(); // TODO fix |
||
330 | ftp_Tell(213, date("YmdHis", $file_date)); |
||
331 | } else { |
||
332 | ftp_Tell(550, "No such file or directory"); |
||
333 | } |
||
334 | break; |
||
335 | } |
||
336 | break; |
||
337 | |||
338 | case 'REST': |
||
339 | $FTP->resume = (int)$args; |
||
340 | ftp_Tell(350, 'Restarting at '.$FTP->resume.'.'); |
||
341 | break; |
||
342 | case 'QUIT': |
||
343 | ftp_Tell(221, "Goodbye."); |
||
344 | /* check if we have to close a 'passive' socket */ |
||
345 | if ($FTP->DC["socket_desc"]) { |
||
346 | socket_close($FTP->DC["socket"]); |
||
347 | } |
||
348 | return 0; |
||
349 | break; |
||
350 | case 'PWD': |
||
351 | $dir=$FTP->cwd; |
||
352 | if ($FTP->listMode) { |
||
353 | $dir="/".SPCHL.$FTP->listMode.SPCHR.$dir; |
||
354 | } |
||
355 | if (strlen($dir)>1) { |
||
356 | $dir=substr($dir,0,-1); |
||
357 | } |
||
358 | ftp_Tell(257, "\"$dir\" is current directory."); |
||
359 | break; |
||
360 | case 'HELP': |
||
361 | ftp_Tell(214, "not implemented" ); |
||
362 | break; |
||
363 | case 'PORT': |
||
364 | $FTP->DC["mode"]="active"; |
||
365 | $host=explode(",",$args); |
||
366 | $address=$host[0].".".$host[1].".".$host[2].".".$host[3]; |
||
367 | $FTP->DC["address"]=$address; |
||
368 | $port=((int)$host[4]) << 8; |
||
369 | $port+=(int)$host[5]; |
||
370 | $FTP->DC["port"]=$port; |
||
371 | ftp_Tell(200, "ok, connecting to $address $port"); |
||
372 | break; |
||
373 | case 'PASV': |
||
374 | $port=ftp_GetPasv(); |
||
375 | if ($port) { |
||
376 | ftp_Tell(227, "Entering Passive Mode ($port)"); |
||
377 | } |
||
378 | break; |
||
379 | View Code Duplication | case 'CDUP': |
|
380 | $cwd=$FTP->store->make_path($FTP->cwd, ".."); |
||
381 | if ($FTP->store->exists($FTP->site.$cwd)) { |
||
382 | $FTP->cwd=$cwd; |
||
383 | ftp_Tell(250, "CDUP succesfull"); |
||
384 | } else { |
||
385 | ftp_Tell(550, "CDUP not succesfull"); |
||
386 | } |
||
387 | break; |
||
388 | case 'CWD': |
||
389 | /* if CWD path is absolute then listmode is set to |
||
390 | the default value */ |
||
391 | |||
392 | $absolute = ($args[0]=="/") ? true : false; |
||
393 | if ($absolute) { |
||
394 | $FTP->listMode=$FTP->defaultListMode; |
||
395 | } |
||
396 | |||
397 | $path=$FTP->store->make_path($FTP->cwd, $args); |
||
398 | debug("ftp: cwd absolute path is ($path)"); |
||
399 | View Code Duplication | while (preg_match('|/'.ESPCHL.'([^/]*)'.ESPCHR.'/|', $path, $regs) && $regs[1]) { |
|
400 | $FTP->listMode=$regs[1]; |
||
401 | $path=str_replace("/".SPCHL.$FTP->listMode.SPCHR."/", "/", $path); |
||
402 | } |
||
403 | $cwd=$FTP->store->make_path($FTP->cwd, $path); |
||
404 | if ($FTP->store->exists($FTP->site.$cwd)) { |
||
405 | $result=current($FTP->store->call("system.get.phtml", "", |
||
406 | $FTP->store->get($FTP->site.$cwd))); |
||
407 | if ($result->type==="pshortcut") { |
||
408 | debug("ftp: shortcut: ".$result->data->path); |
||
409 | $cwd=$FTP->store->make_path($cwd, $result->data->path); |
||
410 | } |
||
411 | |||
412 | $FTP->cwd=$cwd; |
||
413 | debug("ftp: cwd ($cwd) listmode(".$FTP->listMode.")"); |
||
414 | ftp_Tell(250, "CWD succesfull (listmode = ".$FTP->listMode.")"); |
||
415 | } else { |
||
416 | ftp_Tell(550, "'$cwd' no such file or directory"); |
||
417 | } |
||
418 | break; |
||
419 | |||
420 | case 'TYPE': |
||
421 | if (preg_match('/a|i/i', $args)) { |
||
422 | $FTP->DC["type"]=strtoupper($args); |
||
423 | ftp_Tell(200, "Type set to ".$args); |
||
424 | } else { |
||
425 | ftp_Tell(500, "Type $args not valid"); |
||
426 | } |
||
427 | break; |
||
428 | |||
429 | case 'SIZE': |
||
430 | $path = $args; |
||
431 | ftp_TranslatePath($path, $listMode); |
||
432 | switch ($listMode) { |
||
433 | View Code Duplication | case 'templates': |
|
434 | ftp_TranslateTemplate($path, $template); |
||
435 | |||
436 | $result = current( |
||
437 | $FTP->store->call("ftp.template.exists.phtml", |
||
438 | array("arRequestedTemplate" => $template), |
||
439 | $FTP->store->get($path))); |
||
440 | if (is_array($result)) { |
||
441 | $file_size = $result["size"]; |
||
442 | ftp_Tell(213, (int)$file_size); |
||
443 | } else { |
||
444 | ftp_Tell(550, "No such file or directory"); |
||
445 | } |
||
446 | |||
447 | break; |
||
448 | View Code Duplication | default: |
|
449 | if ($FTP->store->exists($path)) { |
||
450 | $size = $FTP->store->call( |
||
451 | "ftp.$listMode.size.phtml", |
||
452 | "", |
||
453 | $FTP->store->get($path)); |
||
454 | ftp_Tell(213, (int)$size[0]); |
||
455 | } else { |
||
456 | ftp_Tell(550, "No such file or directory"); |
||
457 | } |
||
458 | break; |
||
459 | } |
||
460 | break; |
||
461 | |||
462 | case 'RNFR': |
||
463 | $rename_src_path = $args; |
||
464 | ftp_TranslatePath($rename_src_path, $rename_src_listMode); |
||
465 | if ($listMode === "templates") { |
||
466 | ftp_TranslateTemplate($rename_src_path, $rename_src_template); |
||
467 | $result = $FTP->store->call( |
||
468 | "ftp.template.exists.phtml", |
||
469 | array( |
||
470 | "arRequestedTemplate" => $rename_src_template |
||
471 | ), |
||
472 | $FTP->store->get($path)); |
||
473 | |||
474 | if (is_array($result) && current($result)) { |
||
475 | ftp_Tell(350, "template exists, supply destination name."); |
||
476 | } else { |
||
477 | ftp_Tell(550, "template [".$rename_src_template."] does not exists."); |
||
478 | $rename_src_path = ""; |
||
479 | } |
||
480 | |||
481 | } else if ($FTP->store->exists($rename_src_path)) { |
||
482 | ftp_Tell(350, "Object exists, supply destination name."); |
||
483 | } else { |
||
484 | ftp_Tell(550, "Object [".$rename_src_path."] does not exists."); |
||
485 | $rename_src_path = ""; |
||
486 | } |
||
487 | break; |
||
488 | |||
489 | case 'RNTO': |
||
490 | if ($rename_src_path) { |
||
491 | $rename_dest_path = $args; |
||
492 | ftp_TranslatePath($rename_dest_path, $rename_dest_listMode); |
||
493 | if ($rename_dest_listMode === $rename_src_listMode) { |
||
494 | if ($rename_dest_listMode === "templates") { |
||
495 | $temp = $args; |
||
496 | if ($temp[strlen($temp)-1] === "/") { |
||
497 | $rename_dest_template = $rename_src_template; |
||
498 | } else { |
||
499 | ftp_TranslateTemplate($rename_dest_path, $rename_dest_template); |
||
500 | } |
||
501 | $do_move = $FTP->store->exists($rename_dest_path); |
||
502 | } else { |
||
503 | if ($FTP->store->exists($rename_dest_path)) { |
||
504 | $parent = $FTP->store->make_path($rename_src_path, ".."); |
||
505 | $file = substr($rename_src_path, strlen($parent)); |
||
506 | $rename_dest_path.=$file; |
||
507 | } |
||
508 | $do_move = !$FTP->store->exists($rename_dest_path); |
||
509 | } |
||
510 | |||
511 | if ($do_move) { |
||
512 | debug("ftp::RENAME ($rename_src_path, $rename_dest_path, ".$rename_src_listMode.", $rename_src_template, $rename_dest_template)"); |
||
513 | $FTP->store->call("ftp.".$rename_src_listMode.".rename.phtml", |
||
514 | array( |
||
515 | "source" => $rename_src_path, |
||
516 | "target" => $rename_dest_path, |
||
517 | "source_template" => $rename_src_template, |
||
518 | "target_template" => $rename_dest_template |
||
519 | ), |
||
520 | $FTP->store->get($rename_src_path)); |
||
521 | |||
522 | View Code Duplication | if ($ARCurrent->ftp_error) { |
|
523 | ftp_Tell(550, $ARCurrent->ftp_error); |
||
524 | unset($ARCurrent->ftp_error); |
||
525 | } else { |
||
526 | ftp_Tell(250, "Rename successfull."); |
||
527 | } |
||
528 | $rename_src_path = ""; |
||
529 | } else { |
||
530 | ftp_Tell(550, "Object [".$args."] does already exist."); |
||
531 | } |
||
532 | } else { |
||
533 | ftp_Tell(550, "Moving objects between different modeses is not supported (yet)."); |
||
534 | } |
||
535 | } else { |
||
536 | ftp_Tell(550, "Expected RNFR"); |
||
537 | } |
||
538 | break; |
||
539 | |||
540 | case 'RETR': |
||
541 | $path=$args; |
||
542 | ftp_TranslatePath($path, $listMode); |
||
543 | switch ($listMode) { |
||
544 | case "templates": |
||
545 | ftp_TranslateTemplate($path, $template); |
||
546 | $getmode = "templates"; |
||
547 | |||
548 | $result = current( |
||
549 | $FTP->store->call("ftp.template.exists.phtml", |
||
550 | array("arRequestedTemplate" => $template), |
||
551 | $FTP->store->get($path))); |
||
552 | $file_size = $result["size"]; |
||
553 | break; |
||
554 | default: |
||
555 | $file_size = current( |
||
556 | $FTP->store->call("ftp.files.size.phtml", "", |
||
557 | $FTP->store->get($path))); |
||
558 | $getmode = "files"; |
||
559 | break; |
||
560 | } |
||
561 | |||
562 | debug("ftp: opening $path / template $template"); |
||
563 | |||
564 | if (ftp_OpenDC()!==false) { |
||
565 | if ($FTP->store->exists($path)) { |
||
566 | |||
567 | $file_size -= $FTP->resume; |
||
568 | ftp_Tell(150, "Opening ".(($FTP->DC["type"]==="A") ? 'ASCII' : 'BINARY')." mode data connection for $args ($file_size bytes)"); |
||
569 | $FTP->store->call("ftp.$getmode.get.phtml", array("arRequestedTemplate" => $template), |
||
570 | $FTP->store->get($path)); |
||
571 | debug("ftp::get::going to close dc"); |
||
572 | ftp_CloseDC(); |
||
573 | debug("ftp::get::dc closed"); |
||
574 | ftp_Tell(226, "Transfer complete"); |
||
575 | } else { |
||
576 | ftp_CloseDC(); |
||
577 | ftp_Tell(550, "$file does not exist"); |
||
578 | } |
||
579 | } |
||
580 | break; |
||
581 | |||
582 | case 'NLST': |
||
583 | case 'LIST': |
||
584 | $args = chop($args); |
||
585 | // only use the last word (some clients issue LIST -l [filename]) |
||
586 | $args=preg_replace('/(-[^[:space:]]+)?[[:space:]]*([^[:space:]]*)$/', '\2', $args); |
||
587 | debug("LIST ARGS($args)"); |
||
588 | $path = $args; |
||
589 | ftp_TranslatePath($path, $listMode); |
||
590 | debug("ftp: LIST path=$path, mode=$listMode"); |
||
591 | if ($FTP->store->exists($path)) { |
||
592 | |||
593 | ftp_Tell(150, "Opening ".(($FTP->DC["type"]==="A") ? 'ASCII' : 'BINARY')." mode data connection"); |
||
594 | if (ftp_OpenDC()!==false) { |
||
595 | $mode = array(); |
||
596 | debug("ftp: listing ($path) ($listMode)"); |
||
597 | |||
598 | if ($FTP->symlinkListModes) { |
||
599 | View Code Duplication | if ($listMode!=="files") { |
|
600 | $mode["filename"]=SPCHL."files".SPCHR; |
||
601 | $mode["date"]=time(); |
||
602 | if ($FTP->cwd!=="/") { |
||
603 | $mode["type"]="shortcut"; |
||
604 | $mode["target"]=$FTP->cwd; |
||
605 | if ($FTP->defaultListMode!="files") { |
||
606 | $mode["target"]="/".SPCHL."files".SPCHR.$mode["target"]; |
||
607 | } |
||
608 | } else { |
||
609 | $mode["type"]="dir"; |
||
610 | } |
||
611 | $mode["size"]=0; |
||
612 | $mode["grants"]["read"]=true; |
||
613 | |||
614 | if ($cmd!=="NLST") { |
||
615 | $data=ftp_GenListEntry($mode); |
||
616 | echo "$data"; |
||
617 | } else { |
||
618 | echo $mode["filename"]."\n"; |
||
619 | } |
||
620 | } |
||
621 | |||
622 | View Code Duplication | if ($listMode!=="templates") { |
|
623 | $mode["filename"]=SPCHL."templates".SPCHR; |
||
624 | $mode["date"]=time(); |
||
625 | if ($FTP->cwd!=="/") { |
||
626 | $mode["type"]="shortcut"; |
||
627 | $mode["target"]=$FTP->cwd; |
||
628 | if ($FTP->defaultListMode!="templates") { |
||
629 | $mode["target"]="/".SPCHL."templates".SPCHR.$mode["target"]; |
||
630 | } |
||
631 | } else { |
||
632 | $mode["type"]="dir"; |
||
633 | } |
||
634 | $mode["size"]=0; |
||
635 | $mode["grants"]["read"]=true; |
||
636 | if ($cmd!=="NLST") { |
||
637 | $data=ftp_GenListEntry($mode); |
||
638 | echo "$data"; |
||
639 | } else { |
||
640 | echo $mode["filename"]."\n"; |
||
641 | } |
||
642 | } |
||
643 | |||
644 | View Code Duplication | if ($listMode!=="objects") { |
|
645 | $mode["filename"]=SPCHL."objects".SPCHR; |
||
646 | $mode["date"]=time(); |
||
647 | $mode["size"]=0; |
||
648 | $mode["grants"]["read"]=true; |
||
649 | if ($FTP->cwd!=="/") { |
||
650 | $mode["type"]="shortcut"; |
||
651 | $mode["target"]=$FTP->cwd; |
||
652 | if ($FTP->defaultListMode!="objects") { |
||
653 | $mode["target"]="/".SPCHL."objects".SPCHR.$mode["target"]; |
||
654 | } |
||
655 | } else { |
||
656 | $mode["type"]="dir"; |
||
657 | } |
||
658 | if ($cmd!=="NLST") { |
||
659 | $data=ftp_GenListEntry($mode); |
||
660 | echo "$data"; |
||
661 | } else { |
||
662 | echo $mode["filename"]."\n"; |
||
663 | } |
||
664 | } |
||
665 | } |
||
666 | $template="ftp.".$listMode.".list.phtml"; |
||
667 | $result=current($FTP->store->call($template, "", |
||
668 | $FTP->store->get($path))); |
||
669 | |||
670 | debug("ftp: results(".sizeof($result).")"); |
||
671 | @reset($result); |
||
672 | foreach ( $result as $entry ) { |
||
673 | debug("ftp: file path = (".$entry["path"].")"); |
||
674 | View Code Duplication | if ($cmd!=="NLST") { |
|
675 | $data=ftp_GenListEntry($entry); |
||
676 | echo "$data"; |
||
677 | } else { |
||
678 | $parent = $FTP->store->make_path($entry["path"], ".."); |
||
679 | $filename = $entry["path"] ? substr($entry["path"], strlen($parent), -1) : $entry["filename"]; |
||
680 | debug("ftp::nlst ".$filename); |
||
681 | echo $filename."\n"; |
||
682 | } |
||
683 | } |
||
684 | |||
685 | ftp_CloseDC(); |
||
686 | ftp_Tell(226, "Transfer complete"); |
||
687 | } else { |
||
688 | ftp_Tell(550, "Could not connect to client"); |
||
689 | debug("ftp: could not connect"); |
||
690 | } |
||
691 | } else { |
||
692 | ftp_TranslateTemplate($path, $template); |
||
693 | debug("ftp::list maybe it's a template? ($path, $template)"); |
||
694 | $result = current($FTP->store->call("ftp.template.exists.phtml", |
||
695 | array("arRequestedTemplate" => $template), |
||
696 | $FTP->store->get($path))); |
||
697 | |||
698 | if (is_array($result)) { |
||
699 | ftp_Tell(150, "Opening ".(($FTP->DC["type"]==="A") ? 'ASCII' : 'BINARY')." mode data connection"); |
||
700 | if (ftp_OpenDC()!==false) { |
||
701 | View Code Duplication | if ($cmd!=="NLST") { |
|
702 | echo ftp_GenListEntry($result); |
||
703 | } else { |
||
704 | $parent = $FTP->store->make_path($result["path"], ".."); |
||
705 | $filename = $result["path"] ? substr($result["path"], strlen($parent), -1) : $result["filename"]; |
||
706 | debug("ftp::nlst ".$filename); |
||
707 | echo $filename."\n"; |
||
708 | } |
||
709 | ftp_CloseDC(); |
||
710 | ftp_Tell(226, "Transfer complete"); |
||
711 | } else { |
||
712 | ftp_Tell(550, "Could not connect to client"); |
||
713 | debug("ftp: could not connect"); |
||
714 | } |
||
715 | } else { |
||
716 | ftp_Tell(550, "Directory not found"); |
||
717 | } |
||
718 | } |
||
719 | break; |
||
720 | |||
721 | case 'RMD': |
||
722 | case 'RMDIR': |
||
723 | case 'DELE': |
||
724 | $target = $args; |
||
725 | ftp_TranslatePath($target, $listMode); |
||
726 | |||
727 | debug("ftp: removing $target"); |
||
728 | if ($listMode==="templates") { |
||
729 | $path = $FTP->store->make_path($target, ".."); |
||
730 | $template = substr($target, strlen($path), -1); |
||
731 | debug("ftp: removing template ($path) ($template)"); |
||
732 | $FTP->store->call("ftp.templates.delete.phtml", array("template" => $template), |
||
733 | $FTP->store->get($path)); |
||
734 | |||
735 | ftp_Tell(250, "$template removed"); |
||
736 | } else if ($FTP->store->exists($target)) { |
||
737 | debug("ftp::delete ($target) ftp.$listMode.delete.phtml"); |
||
738 | $FTP->store->call("ftp.$listMode.delete.phtml", "", |
||
739 | $FTP->store->get($target)); |
||
740 | |||
741 | View Code Duplication | if ($ARCurrent->ftp_error) { |
|
742 | ftp_Tell(550, $ARCurrent->ftp_error); |
||
743 | unset($ARCurrent->ftp_error); |
||
744 | } else { |
||
745 | ftp_Tell(250, "$target removed"); |
||
746 | } |
||
747 | } else { |
||
748 | ftp_Tell(550, "$target does not exist"); |
||
749 | } |
||
750 | break; |
||
751 | |||
752 | case 'STOR': |
||
753 | $target = $args; |
||
754 | ftp_TranslatePath($target, $listMode); |
||
755 | $path = $FTP->store->make_path($target, ".."); |
||
756 | |||
757 | ftp_Tell(150, "Opening ".(($FTP->DC["type"]==="A") ? 'ASCII' : 'BINARY')." mode data connection"); |
||
758 | debug("ftp: client wants to store file ($target)"); |
||
759 | preg_match('|^/(.*/)?[^./]*[.]([^./]+)/$|i', $target, $regs); |
||
760 | $ext = $regs[2]; |
||
761 | if (ftp_OpenDC()) { |
||
762 | $tempfile=tempnam($FTP->store->get_config('files')."temp/", "upload"); |
||
763 | debug("tempfile: '$tempfile' ext: '$ext'"); |
||
764 | $tempfile.=$ext; |
||
765 | $fp=fopen($tempfile, "wb"); |
||
766 | $fileinfo = array(); |
||
767 | if ($fp) { |
||
768 | $fileinfo["tmp_name"]=$tempfile; |
||
769 | if ($listMode === "templates") { |
||
770 | ftp_TranslateTemplate($target, $template); |
||
771 | $fileinfo["name"]=preg_replace('/[^.a-z0-9_-]/i', '_', $template); |
||
772 | |||
773 | debug("ftp: writing to $tempfile\n"); |
||
774 | if ($FTP->resume) { |
||
775 | debug("ftp::store resuming file at $FTP->resume"); |
||
776 | ob_start(); |
||
777 | $FTP->store->call("ftp.$listMode.get.phtml", array("arRequestedTemplate" => $template), |
||
778 | $FTP->store->get($target)); |
||
779 | $data=ob_get_contents(); |
||
780 | fwrite($fp, substr($data, 0, $FTP->resume)); |
||
781 | ob_end_clean(); |
||
782 | } |
||
783 | while (($data=ftp_ReadDC())) { |
||
784 | fwrite($fp, $data); |
||
785 | } |
||
786 | fclose($fp); |
||
787 | ftp_CloseDC(); |
||
788 | $fileinfo["type"]=get_mime_type($tempfile); |
||
789 | View Code Duplication | if (!$fileinfo["type"]) { |
|
790 | $fileinfo["type"]=get_mime_type($fileinfo["name"], MIME_EXT); |
||
791 | } |
||
792 | $fileinfo["size"]=filesize($tempfile); |
||
793 | |||
794 | debug("ftp: writing template to ($target$template)"); |
||
795 | $FTP->store->call("ftp.templates.save.phtml", array("file" => $fileinfo), |
||
796 | $FTP->store->get($target)); |
||
797 | } else { |
||
798 | $file=substr($target, strlen($path), -1); |
||
799 | $fileinfo["name"]=preg_replace('/[^.a-z0-9_-]/i', '_', $file); |
||
800 | if ($FTP->store->exists($target)) { |
||
801 | debug("ftp::store updating $target"); |
||
802 | debug("ftp: writing to $tempfile\n"); |
||
803 | if ($FTP->resume) { |
||
804 | debug("ftp::store resuming file at $FTP->resume"); |
||
805 | ob_start(); |
||
806 | $FTP->store->call("ftp.$listMode.get.phtml", "", |
||
807 | $FTP->store->get($target)); |
||
808 | $data=ob_get_contents(); |
||
809 | debug("ftp::store resume pre-read ".strlen($data)); |
||
810 | fwrite($fp, substr($data, 0, $FTP->resume)); |
||
811 | ob_end_clean(); |
||
812 | } |
||
813 | while (($data=ftp_ReadDC())) { |
||
814 | fwrite($fp, $data); |
||
815 | } |
||
816 | fclose($fp); |
||
817 | ftp_CloseDC(); |
||
818 | |||
819 | $fileinfo["type"]=get_mime_type($tempfile); |
||
820 | View Code Duplication | if (!$fileinfo["type"]) { |
|
821 | $fileinfo["type"]=get_mime_type($fileinfo["name"], MIME_EXT); |
||
822 | } |
||
823 | $fileinfo["size"]=filesize($tempfile); |
||
824 | debug("ftp::store total size of fileupload is: ".$fileinfo["size"]); |
||
825 | // if $target already exists |
||
826 | $FTP->store->call("ftp.$listMode.save.phtml", array("file" => $fileinfo), |
||
827 | $FTP->store->get($target)); |
||
828 | } else { |
||
829 | debug("ftp::store storing $target"); |
||
830 | debug("ftp: writing to $tempfile\n"); |
||
831 | while (($data=ftp_ReadDC())) { |
||
832 | fwrite($fp, $data); |
||
833 | } |
||
834 | fclose($fp); |
||
835 | ftp_CloseDC(); |
||
836 | |||
837 | $fileinfo["type"]=get_mime_type($tempfile); |
||
838 | View Code Duplication | if (!$fileinfo["type"]) { |
|
839 | $fileinfo["type"]=get_mime_type($fileinfo["name"], MIME_EXT); |
||
840 | } |
||
841 | $fileinfo["size"]=filesize($tempfile); |
||
842 | |||
843 | $FTP->store->call("ftp.$listMode.save.new.phtml", array("file" => $fileinfo), |
||
844 | $FTP->store->get($path)); |
||
845 | } |
||
846 | } |
||
847 | if (file_exists($tempfile)) { |
||
848 | @unlink($tempfile); |
||
849 | } |
||
850 | |||
851 | } else { |
||
852 | debug("ftp: could not write to $filename\n"); |
||
853 | } |
||
854 | |||
855 | if ($ARCurrent->ftp_error) { |
||
856 | ftp_Tell(550, $ARCurrent->ftp_error); |
||
857 | unset($ARCurrent->ftp_error); |
||
858 | } else { |
||
859 | ftp_Tell(226, "Transfer complete (".$fileinfo["name"].")"); |
||
860 | } |
||
861 | } else { |
||
862 | debug("ftp: error connecting to client"); |
||
863 | ftp_Tell(550, "Could not establish a connection"); |
||
864 | } |
||
865 | break; |
||
866 | |||
867 | case 'MKD': |
||
868 | $path_requested = $args; |
||
869 | $path=preg_replace("|/".ESPCHL.'[^/]*'.ESPCHR."/|", "/", $args); |
||
870 | preg_match('|^(.*[/])?(.*)$|i', $path, $regs); |
||
871 | $arNewFilename=preg_replace('/[^.a-z0-9_-]/i', '_', $regs[2]); |
||
872 | |||
873 | $path=$FTP->site.$FTP->store->make_path($FTP->cwd, $path); |
||
874 | $parent=$FTP->store->make_path($path, ".."); |
||
875 | |||
876 | debug("ftp: mkdir: name = '$arNewFilename' path = '$path' parent = '$parent'"); |
||
877 | |||
878 | if ($FTP->store->exists($parent)) { |
||
879 | if (!$FTP->store->exists($path)) { |
||
880 | $FTP->store->call("ftp.mkdir.phtml", array("arNewFilename" => $arNewFilename), |
||
881 | $FTP->store->get($parent)); |
||
882 | } else { |
||
883 | $ARCurrent->ftp_error="Directory already exists"; |
||
884 | } |
||
885 | } else { |
||
886 | $ARCurrent->ftp_error="Could not find path $parent"; |
||
887 | } |
||
888 | |||
889 | View Code Duplication | if ($ARCurrent->ftp_error) { |
|
890 | ftp_Tell(550, $ARCurrent->ftp_error); |
||
891 | unset($ARCurrent->ftp_error); |
||
892 | } else { |
||
893 | ftp_Tell(257, "\"$path_requested\" - Directory successfully created."); |
||
894 | } |
||
895 | break; |
||
896 | |||
897 | case 'SYST': |
||
898 | ftp_Tell(215, "UNIX Type: L8"); |
||
899 | break; |
||
900 | |||
901 | case 'NOOP': |
||
902 | ftp_Tell(200, "NOOP command successful"); |
||
903 | break; |
||
904 | |||
905 | case 'USER': |
||
906 | case 'PASS': |
||
907 | ftp_Tell(530, "User '$FTP->user' already logged in"); |
||
908 | break; |
||
909 | |||
910 | default: |
||
911 | ftp_Tell(500, "Function $cmd not implemented (yet)."); |
||
912 | break; |
||
913 | } |
||
914 | $last_cmd = $cmd; |
||
915 | } |
||
916 | } |
||
917 | |||
1129 |
If you define a variable conditionally, it can happen that it is not defined for all execution paths.
Let’s take a look at an example:
In the above example, the variable $x is defined if you pass “foo” or “bar” as argument for $a. However, since the switch statement has no default case statement, if you pass any other value, the variable $x would be undefined.
Available Fixes
Check for existence of the variable explicitly:
Define a default value for the variable:
Add a value for the missing path: